# when i am plotting this conditional for loop program no plot is showing only one dot is showing. Can anyone help me about how to display plot? i am using Matlab 2013..

조회 수: 1(최근 30일)
ashutosh negi 2016년 7월 31일
답변: VBBV 2021년 11월 28일
% conditional
x= -5:0.005:15;
for k=1:length(x)
if x(k)<0
y(k)=sqrt(x(k)^2+1);
elseif x(k)<=10
y(k)=3*x(k)+1;
elseif x(k)>=10
y(k)=9*sin(5*x(k)-50)+31;
end
end
plot(x(k),y(k),'*--r','linewidth',2,'markeredgecolor','k'),xlabel('x'),ylabel('y')

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

### 답변(2개)

Walter Roberson 2016년 7월 31일
plot(x,y,'*--r','linewidth',2,'markeredgecolor','k')
You were asking to plot only the very last point, x(k) and y(k)
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

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

VBBV 2021년 11월 28일
% conditional
x= -5:0.005:15;
for k=1:length(x)
if x(k)<0
y(k)=sqrt(x(k)^2+1);
elseif x(k)<=10
y(k)=3*x(k)+1;
elseif x(k)>=10
y(k)=9*sin(5*x(k)-50)+31;
end
plot(x(1:k),y(1:k),'*--r','linewidth',1,'markeredgecolor','b'); % you can place the plot command inside loop to view
end
you are using the plot command outside the loop,
Instead you can place it inside the loop as shown and plot the graph

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

### Community Treasure Hunt

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

Start Hunting!

Translated by