ploting variables from a data structure

hi,
i am having four 1x1 structures each contains 50 fields. what i need to do is subplot the 1st field from each structure, save the plot and do the same with the 2nd field from each structure and so on...
I am guessing i need to use a loop on each subplot, to plot each field, but how?

 采纳的回答

KSSV
KSSV 2018-11-13
编辑:KSSV 2018-11-13
% some random structure for demo
S(1).v = rand(10,2) ; S(1).name = 'one' ;
S(2).v = rand(10,2) ; S(3).name = 'two' ;
S(3).v = rand(10,2) ; S(3).name = 'three' ;
N = length(S) ; % length of the structure array
% plot
for i = 1:N
subplot(N,1,i)
plot(S(i).v(:,1),S(i).v(:,2))
title(S(i).name) ;
end

2 个评论

can we do the same if the field names are dynamic, actually the field names are strings which will be needed to save the plots
KSSV
KSSV 2018-11-13
编辑:KSSV 2018-11-13
Very much can be done......why not..check I hve edited the code.

请先登录,再进行评论。

更多回答(1 个)

p = structfun(@plot,S); %an example
p(1).Marker = 'o'; % number 1 represent field 1 marker likewise you can reate a loop for markers alone to differentiate
p(2).Marker = '+';
p(3).Marker = 's';
hold off

1 个评论

i need to plot from different structures, into one plot, using subplot,
suppose i have four 1x1 structure lets say D1,D2,D3,D4. now each structure is having 50 fields suppose F1,F2,F3,F4,F5,F6,F8.....
so the plot will look like
SUBPLOT(D1.FA) SUBPLOT(D2,F1) SUBPLOT(D3,F1) SUBPLOT(D4,F1)
save it
SUBPLOT(D1,F2) SUBPLOT(D2,F2) SUBPLOT(D3,F2) SUBPLOT(D4,F2)
save it
*i havent writen the syntax of subplot but just trying to show you how the plot needs to look like
and these are spatial plots,
i just need to understand how to use a loop for the above

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by