Got Questions? Get Answers.
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:
How can animate my code for every implementation of loop;

Subject: How can animate my code for every implementation of loop;

From: mahdi roozbhani

Date: 30 Dec, 2010 04:27:04

Message: 1 of 2

PL tell me how can I animate this sphere foe every implementation of for loop ?

clc
clear all
axis equal
[x,y,z]=sphere;
x10=1;
y10=1;
z10=1;
x1=x+x10;
y1=y+y10;
z1=z+z10;
z1=roundn(z1,-4);
x20=1.5;
y20=1.5;
z20=3;
x2=x+x20;
y2=y+y20;
zn=solve('(x20-x10)^2+(y20-y10)^2+(zn-z10)^2=4','zn');
zn=subs(zn,'x10',x10);
zn=subs(zn,'x20',x20);
zn=subs(zn,'y20',y20);
zn=subs(zn,'y10',y10);
zn=subs(zn,'z10',z10);

zn=double(zn);
z2n=zn(zn>0);
z2n=roundn(z2n,-2);
z2=z+z2n;
surf(x2,y2,z2);
hold on
n=(z2n-z10)/.01;
for i=1:n
[THETA1,PHI1,R1] = cart2sph(x20,y20,z2n);
xx=R1*cos(PHI1)*cos(THETA1);
yy=R1*cos(PHI1)*sin(THETA1);
slope=yy/xx;
zz=z2n-i*.01;
solvi=solve('(xx-1)^2+(yy-1)^2+(zz-1)^2=4','-slope*xx+yy=0','xx','yy');
solvix=solvi.xx;
solviy=solvi.yy;
solvix=subs(solvix,'slope',slope);
solvix=subs(solvix,'zz',zz);
solviy=subs(solviy,'slope',slope);
solviy=subs(solviy,'zz',zz);
solvi1=[max(solvix) max(solviy)];
[x,y,z]=sphere;
x4=x+solvi1(1);
y4=y+solvi1(2);
z4=z+1;
pause(0.25);
end
surf(x1,y1,z1);
surf(x4,y4,z4);
hold off

Subject: How can animate my code for every implementation of loop;

From: Nasser M. Abbasi

Date: 30 Dec, 2010 04:43:12

Message: 2 of 2

On 12/29/2010 8:27 PM, mahdi roozbhani wrote:
> PL tell me how can I animate this sphere foe every implementation of for loop ?

One way I've done animation is to make a plot, then do draw now, and
may be add a small pause() after that to slow down the animation.

If you want to keep orginal plot and superimpose on it, use hold on.

--Nasser

Tags for this Thread

No tags are associated with 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