Plot cell data from for loop

3 vues (au cours des 30 derniers jours)
lena kappa
lena kappa le 12 Avr 2022
Commenté : Mathieu NOE le 13 Avr 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 commentaires
KSSV
KSSV le 12 Avr 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 le 12 Avr 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.

Connectez-vous pour commenter.

Réponse acceptée

Mathieu NOE
Mathieu NOE le 12 Avr 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 commentaires
lena kappa
lena kappa le 12 Avr 2022
Thank you @Mathieu NOE.
Mathieu NOE
Mathieu NOE le 13 Avr 2022
My pleasure !

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by