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?

 Akzeptierte Antwort

KSSV
KSSV am 13 Nov. 2018
Bearbeitet: KSSV am 13 Nov. 2018

1 Stimme

% 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 Kommentare

MONTVERT ADAMS
MONTVERT ADAMS am 13 Nov. 2018
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 am 13 Nov. 2018
Bearbeitet: KSSV am 13 Nov. 2018
Very much can be done......why not..check I hve edited the code.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

madhan ravi
madhan ravi am 13 Nov. 2018
Bearbeitet: madhan ravi am 13 Nov. 2018

0 Stimmen

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 Kommentar

MONTVERT ADAMS
MONTVERT ADAMS am 13 Nov. 2018
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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 13 Nov. 2018

Bearbeitet:

am 13 Nov. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by