フィルターのクリア

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 Center および File ExchangeGraphics Performance についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by