Plot cell data from for loop

6 views (last 30 days)
lena kappa
lena kappa on 12 Apr 2022
Commented: Mathieu NOE on 13 Apr 2022
Hi everyone I have the folllowing code which gives me a cell array y{m,ind} and i would like to plot in the same figure
y{1,1}, y{1,2}, y{1,3}up to y{1,5} but i cant figure out how to do it.
Preferably i would like to be able to do this for multiple values of m at the same time(i.e. m=1, m=3, ..).
So to have lets say 3 figures for m=1, m=3 and m=5 and in each on of these figures to have the 5 y{m,ind} plots.
I hope i explained it clearly
outLoop = [2,4,8];
outLoop1 = [1, 3, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100];
for r = 1 : numel(outLoop)
r = outLoop(r);
for m = 1 : numel(outLoop1)
m = outLoop1(m);
for ind=1:5
y{m,ind} = mean(vertcat(y{:,r,m,ind}),1);
end
end
end
  2 Comments
KSSV
KSSV on 12 Apr 2022
What is this
outLoop = al;
The variable is not defined. You can use arrays why use cell array? To plot just use plot.
lena kappa
lena kappa on 12 Apr 2022
Thank you for your answer KSSV.
al= [2,4,8]
but eitherway this is part of a bigger code which i can't upload since i can't upload the corresponding images it analyses.
Thank you for your answer i do know about the command plot but i can't use it correctly for cell array.

Sign in to comment.

Accepted Answer

Mathieu NOE
Mathieu NOE on 12 Apr 2022
hello
maybe this ?
I replaced the " mean(vertcat(y{:,r,m,ind}),1) " by a simple random number
clc
clearvars
outLoop = [2,4,8];
outLoop1 = [1, 3, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100];
al= [2,4,8]
for cr = 1 : numel(outLoop)
r = outLoop(cr);
for cm = 1 : numel(outLoop1)
m = outLoop1(cm);
for ind=1:5
%y{m,ind} = mean(vertcat(y{:,r,m,ind}),1);
y{m,ind} = rand(1,1);
end
figure(cm)
plot([y{m,:}])
end
end

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!