MATLAB Answers

0

Plotting within a nested for loop

Asked by Sydnie Schmidt on 14 Sep 2019 at 1:04
Latest activity Answered by the cyclist
on 14 Sep 2019 at 1:10
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

  0 Comments

Sign in to comment.

1 Answer

Answer by the cyclist
on 14 Sep 2019 at 1:10

I'm guessing you wanted something like
plot(x2,y,'.')
or possibly
plot(x2,y)

  0 Comments

Sign in to comment.