필터 지우기
필터 지우기

Plotting loops, but only empty plot

조회 수: 2 (최근 30일)
Katrina
Katrina 2015년 9월 17일
답변: Star Strider 2015년 9월 17일
I'm trying to plot the information from my loops, but all I am getting is an empty plot. My code is as follows:
x1 = 1;
while x1<19;
y1(x1)=x1^3-(5*x1)^2+2^x1-10000*x1;
x1=x1+1;
end
for x2=1:20
y2(x2)=20000*log(x2)-3*x2;
x2=x2+1;
end
%Create the plot
figure
plot(x1,y1,'b-',x2,y2,'k-')

채택된 답변

Star Strider
Star Strider 2015년 9월 17일
Add ‘x’ as an index to create your ‘x1’ vector, and specify x2 as a vector outside the loop:
x = 1;
while x<19;
x1(x) = x;
y1(x)=x1(x)^3-(5*x1(x))^2+2^x1(x)-10000*x1(x);
x=x+1;
end
for x2=1:20
y2(x2)=20000*log(x2)-3*x2;
end
x2=1:20;
%Create the plot
figure
plot(x1,y1,'b-',x2,y2,'k-')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by