Plotting within a nested for loop

1 visualización (últimos 30 días)
Sydnie Schmidt
Sydnie Schmidt el 14 de Sept. de 2019
Respondida: the cyclist el 14 de Sept. de 2019
Hello I can't see to find the problem within code. I need to plot the corresponding x2 value for all 20 iterations.
x2=0:1:10;
y=0:1:10;
hold on
for j = 1:20
for k = 1:length(x2)
m = randi([0 1]);
if m == 0
x2(k) = x2(k) + 1;
else
x2(k) = x2(k) - 1;
end
plot(x2(k),y)
end
end

Respuestas (1)

the cyclist
the cyclist el 14 de Sept. de 2019
I'm guessing you wanted something like
plot(x2,y,'.')
or possibly
plot(x2,y)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by