Plot cell data from for loop

3 次查看(过去 30 天)
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 个评论
KSSV
KSSV 2022-4-12
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 2022-4-12
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.

请先登录,再进行评论。

采纳的回答

Mathieu NOE
Mathieu NOE 2022-4-12
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by