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:
What is wrong on this animation code?

Subject: What is wrong on this animation code?

From: Danna

Date: 25 Jul, 2010 18:40:04

Message: 1 of 6

want to make an animation where the figure rotates

M=[-3,2,-1;4,-2,3;5,-4,-2;-3,2,-1];

rho = pi/8;
figure, plot(M(1,:), M(2,:),'b.-', M(1,:), M(2,:),'*m'),
axis( [-10,10,-10,10]); hold on

RotMatrix=[cos(rho),-sin(rho),0;sin(rho),cos(rho),0;0,0,1];
for i = 1:64
M=M*RotMatrix;
pause(.08)
plot(M(1,:),M(2,:),'-.b',M(1,:),M(2,:),'*m'),

end

Subject: What is wrong on this animation code?

From: us

Date: 25 Jul, 2010 19:10:04

Message: 2 of 6

"Danna " <silver_girl@hotmail.com> wrote in message <i2i0e4$l1m$1@fred.mathworks.com>...
> want to make an animation where the figure rotates
>
> M=[-3,2,-1;4,-2,3;5,-4,-2;-3,2,-1];
>
> rho = pi/8;
> figure, plot(M(1,:), M(2,:),'b.-', M(1,:), M(2,:),'*m'),
> axis( [-10,10,-10,10]); hold on
>
> RotMatrix=[cos(rho),-sin(rho),0;sin(rho),cos(rho),0;0,0,1];
> for i = 1:64
> M=M*RotMatrix;
> pause(.08)
> plot(M(1,:),M(2,:),'-.b',M(1,:),M(2,:),'*m'),
>
> end

a hint:
- peruse ML's stock function

     help comet;
% to learn about animations

us

Subject: What is wrong on this animation code?

From: Jan Simon

Date: 25 Jul, 2010 22:51:03

Message: 3 of 6

Dear Danna,

> want to make an animation where the figure rotates

It would be very helpful if you describe, why you think, your animation code is wrong. Errors? Unexpected results?

Jan

Subject: What is wrong on this animation code?

From: Danna

Date: 25 Jul, 2010 23:12:03

Message: 4 of 6

"Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <i2if4n$1g2$1@fred.mathworks.com>...
> Dear Danna,
>
> > want to make an animation where the figure rotates
>
> It would be very helpful if you describe, why you think, your animation code is wrong. Errors? Unexpected results?
>
> Jan

The figure its suposed to rotate, but it doesnt. I tried to adapt from this code:

M = [1 2 2 1 1; 1 1 2 2 1; 1 1 1 1 1 ];
X = [1 2 2 1 1; 1 1 2 2 1; 1 1 1 1 1 ];
rho = pi/8;
figure, plot(M(1,:), M(2,:),'b.-', M(1,:), M(2,:),'*m'),
axis( [-10,10,-10,10]); hold on
plot(X(1,:), X(2,:),'--g',X(1,:), X(2,:),'xr')
TransOrigin=[1 0 1; 0 1 1; 0 0 1];
TransBack=[1 0 -1; 0 1 -1; 0 0 1];
RotMatrix=[cos(rho) -sin(rho) 0;sin(rho) cos(rho) 0; 0 0 1];
DilMatrix=[1.01 0 0;0 1.01 0; 0 0 1];
CompositionMatrix=TransBack*DilMatrix*RotMatrix*TransOrigin;
for i = 1:64
M= CompositionMatrix*M;
pause(.08)
plot(M(1,:),M(2,:),'-.b',M(1,:),M(2,:),'*m'),
X = CompositionMatrix*X;
pause(.08)
plot(X(1,:),X(2,:),'--g',X(1,:),X(2,:),'xr'), hold on
end

Subject: What is wrong on this animation code?

From: us

Date: 25 Jul, 2010 23:39:04

Message: 5 of 6

"Danna " <silver_girl@hotmail.com> wrote in message <i2igc3$hru$1@fred.mathworks.com>...
> "Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <i2if4n$1g2$1@fred.mathworks.com>...
> > Dear Danna,
> >
> > > want to make an animation where the figure rotates
> >
> > It would be very helpful if you describe, why you think, your animation code is wrong. Errors? Unexpected results?
> >
> > Jan
>
> The figure its suposed to rotate, but it doesnt. I tried to adapt from this code:
>
> M = [1 2 2 1 1; 1 1 2 2 1; 1 1 1 1 1 ];
> X = [1 2 2 1 1; 1 1 2 2 1; 1 1 1 1 1 ];
> rho = pi/8;
> figure, plot(M(1,:), M(2,:),'b.-', M(1,:), M(2,:),'*m'),
> axis( [-10,10,-10,10]); hold on
> plot(X(1,:), X(2,:),'--g',X(1,:), X(2,:),'xr')
> TransOrigin=[1 0 1; 0 1 1; 0 0 1];
> TransBack=[1 0 -1; 0 1 -1; 0 0 1];
> RotMatrix=[cos(rho) -sin(rho) 0;sin(rho) cos(rho) 0; 0 0 1];
> DilMatrix=[1.01 0 0;0 1.01 0; 0 0 1];
> CompositionMatrix=TransBack*DilMatrix*RotMatrix*TransOrigin;
> for i = 1:64
> M= CompositionMatrix*M;
> pause(.08)
> plot(M(1,:),M(2,:),'-.b',M(1,:),M(2,:),'*m'),
> X = CompositionMatrix*X;
> pause(.08)
> plot(X(1,:),X(2,:),'--g',X(1,:),X(2,:),'xr'), hold on
> end

one of the solutions

     M=[1 2 2 1 1; 1 1 2 2 1; 1 1 1 1 1 ];
     X=[1 2 2 1 1; 1 1 2 2 1; 1 1 1 1 1 ];
     rho=pi/8;
     figure;
     axis([-10,10,-10,10]);
     hold on;
     ph1=plot(M(1,:),M(2,:),'b.-',M(1,:),M(2,:),'*m');
     ph2=plot(X(1,:),X(2,:),'--g',X(1,:),X(2,:),'xr');
     TransOrigin=[1 0 1; 0 1 1; 0 0 1];
     TransBack=[1 0 -1; 0 1 -1; 0 0 1];
     RotMatrix=[cos(rho),-sin(rho),0;sin(rho),cos(rho),0;0,0,1];
     DilMatrix=[1.01,0,0;0,1.01,0;0,0,1];
     CompositionMatrix=TransBack*DilMatrix*RotMatrix*TransOrigin;
for i=1:64
     M=CompositionMatrix*M;
     X=CompositionMatrix*X;
     pause(.08);
     set(ph1,...
          {'xdata'},num2cell(M(1,:),2),...
          {'ydata'},num2cell(M(2,:),2));
     pause(.08);
     set(ph2,...
          {'xdata'},num2cell(X(1,:),2),...
          {'ydata'},num2cell(X(2,:),2));
end

us

Subject: What is wrong on this animation code?

From: Steven_Lord

Date: 26 Jul, 2010 03:04:18

Message: 6 of 6



"Danna " <silver_girl@hotmail.com> wrote in message
news:i2igc3$hru$1@fred.mathworks.com...
> "Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message
> <i2if4n$1g2$1@fred.mathworks.com>...
>> Dear Danna,
>>
>> > want to make an animation where the figure rotates
>>
>> It would be very helpful if you describe, why you think, your animation
>> code is wrong. Errors? Unexpected results? Jan
>
> The figure its suposed to rotate, but it doesnt. I tried to adapt from
> this code:

_Figures_ cannot rotate; they always have their title bar to the top of the
screen.

If you want to rotate _axes_ or a graphics object in an axes, use VIEW (for
an axes) or ROTATE (for an object inside an axes.)

*snip*

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

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