is there a way to extract a set of values from a structured array?
3 views (last 30 days)
Show older comments
I have defined a structured array, meas, which is indexed by number of occurrences of a phenomena. Thus, for example, I have: meas(n).ti = 65.32; meas(n).Rt = 200; meas(n).Vt = 10; etc., etc. I want to define a vector of, for example, the times of occurrences (the "ti" values). The pseudo-code would look like: 'TI = meas(1:end).ti' I obviously could do this in a loop: for n=1:nocc; TI(n) = meas(n).ti; end; (where nocc is the # of occurrences.) Is there a way to do this without using a loop?
0 Comments
Accepted Answer
Stephen23
on 4 Jul 2018
Edited: Stephen23
on 4 Jul 2018
[meas.ti]
See also:
4 Comments
Stephen23
on 8 Jul 2018
@David Horton: this is exactly why I avoid working with nested structures: there is no short-cut or convenient syntax to accessing data in nested structures, so you will have to use loops. Note that getfield and setfield do work with nested structures (but only for one individual field at a time).
In the message "dissimilar structures" refers to the fields, not the size, it simply means that the fields do not match up.
Personally I use multi-dimensional arrays as much as possible, because it significantly simplifies the code required to access and process the data. My advice would be to use multi-dimensional arrays, as that is the easiest way to write neat and efficient MATLAB code.
More Answers (0)
See Also
Categories
Find more on Variables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!