How can you extract multiple fields of a structure matching the same logical index condition?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Matthew Lawrence
am 8 Mär. 2017
Beantwortet: Walter Roberson
am 8 Mär. 2017
Let's say I have a structure point with fields x, y and z. I would like to create a structure subpoint which matches point.z>minz.
I can do: subpoint.x=point.x(point.z>minz); subpoint.y=point.y(point.z>minz); subpoint.z=point.z(point.z>minz);
but I was wondering if there was a way of using logical indexing to all fields implicitly (subpoint=point(point.z>minz) doesn't work).
The reason I'm asking is that in my actual example I have a lot of fields and extracting each one individually is taking a bit of time so I was hoping that a single line equivalent, if it exists, might make things go faster.
Thanks,
Matthew
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 8 Mär. 2017
mask = point.z>minz;
subpoint = structfun(@(F) F(mask), point, 'uniform', 0)
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!