is there a way to extract a set of values from a structured array?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
David Horton
am 4 Jul. 2018
Kommentiert: David Horton
am 9 Jul. 2018
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 Kommentare
Akzeptierte Antwort
Stephen23
am 4 Jul. 2018
Bearbeitet: Stephen23
am 4 Jul. 2018
[meas.ti]
See also:
4 Kommentare
Stephen23
am 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Variables 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!