Plot a struct field that is an array of doubles
Ältere Kommentare anzeigen
I have data stored in a struct with fields 'BO' and 'tota' which I want to plot something like:
plot([data.BO], [data.tota])
but the problem is that each element of the 'tota' field is an array. I want to plot all of the array as multiple y values for the single x value. Example data structure and plot below (plotting was accomplished by breaking the single struct into multiple standalone matrix).

In truth, I want to do something like:
figure; hold on;
plot([data.BO],[data.tota(:,1:end-2)],'o')
plot([data.BO],[data.tota(:,end-1)])
plot([data.BO],[data.tota(:,end)])
The best I can do is
b = cell2mat({data.tota}');
plot([data.BO],b(:,1:end-2),'o')
...
But I was wondering if there is a more elegant way to plot directly from the struct without needing to duplicate data into a bunch of temporary variables.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

