Combine plots generated using for loop

조회 수: 2 (최근 30일)
Erik Lenstrup
Erik Lenstrup 2020년 3월 23일
댓글: Erik Lenstrup 2020년 3월 23일
Hi
How do you combine plots generated from a loop, into one plot, as this ecxampel:
The following plots five plots generated within this foor loop:
for i=1:5
figure
x = [0 : 0.01: 10];
y = i*sin(x);
plot(x,y)
end
how do you combine them into one plot?
I have tried:
for i=1:5
hold on
figure
x = [0 : 0.01: 10];
y = i*sin(x);
plot(x,y)
hold off
end
And:
for i=1:5
figure
x = [0 : 0.01: 10];
y = i*sin(x);
hold on
plot(x,y)
hold off
end
But I cant seem to get it.
/Erik

답변 (1개)

Mohammad Sami
Mohammad Sami 2020년 3월 23일
편집: Mohammad Sami 2020년 3월 23일
Did you mean sub plots ?
f = figure;
tiledlayout(f,5,1);
for i=1:5
ax = nexttile
x = [0 : 0.01: 10];
y = i*sin(x);
plot(ax,x,y)
end
Or overlays
f = figure;
ax = axes(f)
hold(ax,'on');
for i=1:5
x = [0 : 0.01: 10];
y = i*sin(x);
plot(ax,x,y)
end
hold(ax,'off');
  댓글 수: 1
Erik Lenstrup
Erik Lenstrup 2020년 3월 23일
Cheers Mohammad
I can see how my question was unclear, I have edited it as I wish to get a plot like the following:
However thank you for answering.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by