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 日

1 投票

% 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 件のコメント

MONTVERT ADAMS
MONTVERT ADAMS 2018 年 11 月 13 日
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 件)

madhan ravi
madhan ravi 2018 年 11 月 13 日
編集済み: madhan ravi 2018 年 11 月 13 日

0 投票

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 件のコメント

MONTVERT ADAMS
MONTVERT ADAMS 2018 年 11 月 13 日
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 ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2018 年 11 月 13 日

編集済み:

2018 年 11 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by