필터 지우기
필터 지우기

Plot not shown in for loop

조회 수: 1 (최근 30일)
Mahmoud Abbas
Mahmoud Abbas 2022년 3월 8일
답변: Torsten 2022년 3월 8일
The plot is not appearing for this simple loop
for i=0:0.01:1
if i<0.5
M=1
elseif i<0.7
M=0.5
else
M=0
end
plot(i,M,'LineWidth',2)
hold on
end

채택된 답변

Torsten
Torsten 2022년 3월 8일
iter = 0;
for i=0:0.01:1
iter = iter + 1;
I(iter) = i;
if i<0.5
M(iter)=1
elseif i<0.7
M(iter)=0.5
else
M(iter)=0
end
end
plot(I,M,'LineWidth',2)

추가 답변 (1개)

Jan
Jan 2022년 3월 8일
Exactly. Give Matlab a chance to update the output by inserting the command:
drawnow
inside the loop.
  댓글 수: 1
Mahmoud Abbas
Mahmoud Abbas 2022년 3월 8일
Still not working :/
It worked when I tried changing the plot command to: plot(i,M,'*') but I want it to draw the piecewise function with clear lines not with asterisk

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

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by