Accessing structure by its name and looping through it
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Eric Christensen
am 18 Sep. 2019
Kommentiert: Stephen23
am 19 Sep. 2019
Hi,
I'm wondering how I can access a structure by its upper level name from a cell array, and loop through it. For example:
Tests = {'Cold Run'
'Warm Run'
'Hot Run'};
for I = 1:length(Tests)
plot(Tests{I}.Time,Tests{I}.Speed);
hold on;
end
Tests{I} is wrong. If it was part of a larger structure, say "Something", then this would work:
Something.(Tests{I}).Time
But what is the proper syntax to do this without an upper structure?
5 Kommentare
Stephen23
am 19 Sep. 2019
Reagrding the original question: you should read this:
Matt J's suggestion to use a structure array is better than using a cell array of scalar structures:
Akzeptierte Antwort
Matt J
am 19 Sep. 2019
Why not organize the data as a struct array?
Tests(1).Time = data1;
Tests(1).Speed = data2;
Tests(2).Time = data3;
Tests(2).Speed = data4;
Tests(3).Time = data5;
Tests(3).Speed = data6;
The indexing of the different scalar structures Tests(j) is now immediate.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Structures 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!