user3590635
user3590635

Reputation: 1

Why aren't the points being displayed?

Why aren't the points being displayed? I am trying to plot four different interpolated points with different symbols on top of the plot. I have to create a legend that has the shapes corresponding to the points.

A=[1.52 -.7;.56 .4]
l=eig(A);
L=max(l);
Xo=[1;0];

for k = 1:50
Xk=A*Xo;
Xo=Xk;
if k == 1
plot(Xo,Xk,'mo');
elseif k == 2
    plot(Xo,Xk,'mx');
elseif k == 3
    plot(Xo,Xk,'m+');
elseif k == 4
    plot(Xo,Xk,'m*');
elseif k == 5
    plot(Xo,Xk,'ms');
else
    plot(Xo,Xk);
end
end

Upvotes: 0

Views: 55

Answers (1)

Floris
Floris

Reputation: 46365

By default, every time you call plot Matlab will clear the figure and "start again".

If you want to plot two things on top of each other, you can use either

hold on

or

hold all

These are subtly different. With hold on, you leave "everything unchanged". The next plot will use the same color as the last one, etc. With hold all, your next plot will be a different color (but it will not erase the previous plot).

Thus you can change your code as follows:

A=[1.52 -.7;.56 .4]
l=eig(A);
L=max(l);
Xo=[1;0];

for k = 1:50
Xk=A*Xo;
Xo=Xk;
if k == 1
    plot(Xo,Xk,'mo');
elseif k == 2
    plot(Xo,Xk,'mx');
elseif k == 3
    plot(Xo,Xk,'m+');
elseif k == 4
    plot(Xo,Xk,'m*');
elseif k == 5
    plot(Xo,Xk,'ms');
else
    plot(Xo,Xk);
end

hold all; % <<<<< this is the extra line

end

This is really very inefficient code though - but the best way to fix that might want to be the subject of another question.

Upvotes: 2

Related Questions