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?

 Accepted Answer

KSSV
KSSV on 13 Nov 2018
Edited: KSSV on 13 Nov 2018
% 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 Comments

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

Sign in to comment.

More Answers (1)

madhan ravi
madhan ravi on 13 Nov 2018
Edited: madhan ravi on 13 Nov 2018
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 Comment

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

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 13 Nov 2018

Edited:

on 13 Nov 2018

Community Treasure Hunt

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

Start Hunting!