Plotting data from struct array
Ältere Kommentare anzeigen
I am having trouble plotting data that is stored in a struct array. The data is stored in the struct array AB. Let's say it is N-dimensional. So, AB(1), AB(2),.., AB(N). Each has various fields and sub-fields. I tried:
plot(AB.fv.tot, AB.sv.tot)
This yields "expected one output form a curly brace or dot indexing expression, but there were N results". I think I understand that. Invoking the same command as:
plot(AB(:).fv.tot, AB(:).sv.tot)
doesn't achieve anything different, which also makes sense. I saw some suggestions to do the following:
plot([AB.fv.tot], [AB.sv.tot])
This too yields the same result. I am really not sure how to call plot with the plot vectors being contained in fields/subfields of a struct array.
2 Kommentare
the cyclist
am 20 Jan. 2023
Can you upload the AB variable? You can use the paper clip icon in the INSERT section of the toolbar.
"Let's say it is N-dimensional. So, AB(1), AB(2),.., AB(N)"
What you describe is N elements of a structure array, not N dimensions.
Yes, structures can be multi-dimensional. Here is a 4D structure:
S = struct('X',cell(5,4,3,2))
Akzeptierte Antwort
Weitere Antworten (1)
Here is one simple example:
t1 = linspace(-pi, pi, 200);
t2 = linspace(-pi, pi, 500);
f1 = 2*sin(t1);
f2 = 3*cos(t1);
f3 = f1./f2;
f4 = f2./f1;
F5 = 2.5* sin(2*t2);
F6 = 3*cos(3*t2);
H(1).Time=t1;
H(2).Time=t2;
H(1).F=f1;
H(2).F=f2;
H(3).F = f3;
H(4).F = f4;
H(1).FUN = F5;
H(2).FUN = F6;
figure
plot(H(1).Time, H(1).F, 'r--', H(1).Time, H(2).F, 'k', 'linewidth', 2)
figure
plot(H(2).Time, H(1).FUN, 'r--', H(2).Time, H(2).FUN, 'k')
Kategorien
Mehr zu Logical 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!


