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

 Respuesta aceptada

Torsten
Torsten el 8 de Mzo. de 2022

0 votos

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)

Más respuestas (1)

Jan
Jan el 8 de Mzo. de 2022

0 votos

Exactly. Give Matlab a chance to update the output by inserting the command:
drawnow
inside the loop.

1 comentario

Mahmoud Abbas
Mahmoud Abbas el 8 de Mzo. de 2022
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

Iniciar sesión para comentar.

Categorías

Productos

Versión

R2021b

Etiquetas

Preguntada:

el 8 de Mzo. de 2022

Respondida:

el 8 de Mzo. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by