How do I create a loop to plot two graphs in each figure ?
Info
This question is closed. Reopen it to edit or answer.
Show older comments
Hi,
I'm trying to plot this on two different figures with a loop:
x=[5:8];
y=cell(1,4);
y{1}=[1:4];
y{2}=[-x.^2];
y{3}=[(x.^3)./2];
y{4}=[8,8,8,8];
figure(1)
subplot(2,1,1)
plot(x,y{1})
hold on
figure(1)
subplot(2,1,2)
plot(x,y{2})
hold on
figure(2)
subplot(2,1,1)
plot(x,y{3})
hold on
figure(2)
subplot(2,1,2)
plot(x,y{4})
I tryed make something like that:
x=[5:8];
y=cell(1,4);
y{1}=[1:4];
y{2}=[-x.^2];
y{3}=[(x.^3)./2];
y{4}=[8,8,8,8];
for num=1:4
for pos=1:2
subplot(2,1,pos)
if num<=2
for num=pos
hold on
figure(1)
plot(x,y{num})
end
else
hold on
figure(2)
plot(x,y{num})
end
end
end
But this is not exactly what I want. If I had more "y" and the same x-axis.For example y{5},y{6},y{7},...How do I create a loop to plot two graphs in each figure ?.
So,for example,if I had ten "y" (y{1} to y{10}) and the same x-axis.The number of figures will be five with two graphs in each figure.
Thanks
Answers (0)
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!