Filter löschen
Filter löschen

Plot cell data from for loop

3 Ansichten (letzte 30 Tage)
lena kappa
lena kappa am 12 Apr. 2022
Kommentiert: Mathieu NOE am 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 Kommentare
KSSV
KSSV am 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 am 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Mathieu NOE
Mathieu NOE am 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
  2 Kommentare
lena kappa
lena kappa am 12 Apr. 2022
Thank you @Mathieu NOE.
Mathieu NOE
Mathieu NOE am 13 Apr. 2022
My pleasure !

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by