Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Plotting after a for loop

1 回表示 (過去 30 日間)
Lukas Arkenklo
Lukas Arkenklo 2020 年 8 月 11 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I'm having trouble plotting the graph in the picture. I've been trying with and without the for loop in the code but i have no idea what i'm doing wrong. please help :(
for x =[-5:5];
if x < 0 ;
y = 0
else if x >= 0 ;
y = 0.5
end
end
end
plot(x,y)
hold on

回答 (1 件)

KSSV
KSSV 2020 年 8 月 11 日
x = -5:5 ;
y = zeros(size(x)) ;
y(x>=0.5) = 0.5 ;
plot(x,y)
  2 件のコメント
Lukas Arkenklo
Lukas Arkenklo 2020 年 8 月 11 日
That does not give the correct graph :(
KSSV
KSSV 2020 年 8 月 11 日
You should refine x.
x = linspace(-5,5,1000) ;
y = zeros(size(x)) ;
y(x>=0.5) = 0.5 ;
plot(x,y)

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by