Plot figures in loop as superimposed top on top

Similar questions should have been asked however I couldn't get a solution.
Plot can superimpose these loop figures onto one another:
figure();
hold all
for i=1:2:11
y=i;
plot(x,y);
end
However, interestingly can't do the same here:
figure();
hold all
for i=1:2:11
y=x.^i;
plot(x,y);
end
What it does is plotting only the last figure. Any ideas why is this?

답변 (1개)

KSSV
KSSV 2016년 11월 19일
편집: KSSV 2016년 11월 19일

0 개 추천

Used hold on after the plot inside loop.

댓글 수: 5

JohnDylon
JohnDylon 2016년 11월 19일
I tested this as well, it doesn't work.
KSSV
KSSV 2016년 11월 19일
편집: KSSV 2016년 11월 19일
figure(); hold on for i=1:2:11 y=i; plot(x,y,'.b'); end
JohnDylon
JohnDylon 2016년 11월 19일
As I mentioned in the original question, it works when you pick y=i, but not for y=x.^i in the loop.
KSSV
KSSV 2016년 11월 20일
What is x?
Is x a vector or scalar? What is/are its value(s) exactly? Give code to generate x.

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

카테고리

질문:

2016년 11월 19일

댓글:

2016년 11월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by