Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Newbie Question. Plotting multiple times

Subject: Newbie Question. Plotting multiple times

From: matt reister

Date: 3 Nov, 2007 20:06:12

Message: 1 of 3

What i am doing is transforming the unit circle 11 times
under a given transform then plotting it each time. However
i am haveing a hard time plotting all 11 transforms. I have
been stuck on this problem for days and my teacher wont
help. It seems like it would be really easy but i cant
figure it out. Here is my code and more detail:

M = [ 1.5, 0; 0, 1];
c = [2; 0; ];
theta=[1:100]/100*2*pi;
x=cos(theta);
y=sin(theta);
vNew = [x; y;];
M2 = [cos(pi/5), sin(pi/5); -sin(pi/5), cos(pi/5);];

for i = 1:11

    for n = 1:100
        
        vNew(:,n) = M*M2*vNew(:,n) + M2*c;
        
    end
    
  plot(vNew(1,:),vNew(2,:));
  
end


It seems to me that the transform is working fine, but it
seems that when it goes through the plot sequence the last
plot overides the previos plot. I need all eleven plots
including the original vector vNew to be ploted on the same
graph. What would be the easyest way to go about doing this?

Subject: Newbie Question. Plotting multiple times

From: Lorenzo

Date: 3 Nov, 2007 20:14:50

Message: 2 of 3

"matt reister" <mattreister@hotmail.com> wrote in message
<fgikbk$95t$1@fred.mathworks.com>...
> What i am doing is transforming the unit circle 11 times
> under a given transform then plotting it each time. However
> i am haveing a hard time plotting all 11 transforms. I have
> been stuck on this problem for days and my teacher wont
> help. It seems like it would be really easy but i cant
> figure it out. Here is my code and more detail:
>
> M = [ 1.5, 0; 0, 1];
> c = [2; 0; ];
> theta=[1:100]/100*2*pi;
> x=cos(theta);
> y=sin(theta);
> vNew = [x; y;];
> M2 = [cos(pi/5), sin(pi/5); -sin(pi/5), cos(pi/5);];
>
> for i = 1:11
>
> for n = 1:100
>
> vNew(:,n) = M*M2*vNew(:,n) + M2*c;
>
> end
>
> plot(vNew(1,:),vNew(2,:));
>
> end
>
>
> It seems to me that the transform is working fine, but it
> seems that when it goes through the plot sequence the last
> plot overides the previos plot. I need all eleven plots
> including the original vector vNew to be ploted on the same
> graph. What would be the easyest way to go about doing this?

Add
figure
hold on
before the loop. This creates a new figure and turns on the hold property, so
that plots are superimposed and don't replace old ones. If instead of "hold on"
you use "hold all", the colors of the curves will be automatically changed.
hth
Lorenzo

Subject: Newbie Question. Plotting multiple times

From: matt reister

Date: 3 Nov, 2007 21:42:43

Message: 3 of 3

"Lorenzo " <lorenz4matlab@gmail.com> wrote in message
<fgikrq$en2$1@fred.mathworks.com>...
> "matt reister" <mattreister@hotmail.com> wrote in message
> <fgikbk$95t$1@fred.mathworks.com>...
> > What i am doing is transforming the unit circle 11
times
Thank you sir. Worked like a charm.


> > under a given transform then plotting it each time.
However
> > i am haveing a hard time plotting all 11 transforms. I
have
> > been stuck on this problem for days and my teacher wont
> > help. It seems like it would be really easy but i cant
> > figure it out. Here is my code and more detail:
> >
> > M = [ 1.5, 0; 0, 1];
> > c = [2; 0; ];
> > theta=[1:100]/100*2*pi;
> > x=cos(theta);
> > y=sin(theta);
> > vNew = [x; y;];
> > M2 = [cos(pi/5), sin(pi/5); -sin(pi/5), cos(pi/5);];
> >
> > for i = 1:11
> >
> > for n = 1:100
> >
> > vNew(:,n) = M*M2*vNew(:,n) + M2*c;
> >
> > end
> >
> > plot(vNew(1,:),vNew(2,:));
> >
> > end
> >
> >
> > It seems to me that the transform is working fine, but
it
> > seems that when it goes through the plot sequence the
last
> > plot overides the previos plot. I need all eleven plots
> > including the original vector vNew to be ploted on the
same
> > graph. What would be the easyest way to go about doing
this?
>
> Add
> figure
> hold on
> before the loop. This creates a new figure and turns on
the hold property, so
> that plots are superimposed and don't replace old ones.
If instead of "hold on"
> you use "hold all", the colors of the curves will be
automatically changed.
> hth
> Lorenzo
>
>

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us