Plotting after a for loop
Informazioni
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
Mostra commenti meno recenti
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
Risposte (1)
KSSV
il 11 Ago 2020
x = -5:5 ;
y = zeros(size(x)) ;
y(x>=0.5) = 0.5 ;
plot(x,y)
2 Commenti
Lukas Arkenklo
il 11 Ago 2020
KSSV
il 11 Ago 2020
You should refine x.
x = linspace(-5,5,1000) ;
y = zeros(size(x)) ;
y(x>=0.5) = 0.5 ;
plot(x,y)
Questa domanda è chiusa.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!