matlab动画制作Word文件下载.docx

上传人:b****3 文档编号:7394285 上传时间:2023-05-08 格式:DOCX 页数:20 大小:325.15KB
下载 相关 举报
matlab动画制作Word文件下载.docx_第1页
第1页 / 共20页
matlab动画制作Word文件下载.docx_第2页
第2页 / 共20页
matlab动画制作Word文件下载.docx_第3页
第3页 / 共20页
matlab动画制作Word文件下载.docx_第4页
第4页 / 共20页
matlab动画制作Word文件下载.docx_第5页
第5页 / 共20页
matlab动画制作Word文件下载.docx_第6页
第6页 / 共20页
matlab动画制作Word文件下载.docx_第7页
第7页 / 共20页
matlab动画制作Word文件下载.docx_第8页
第8页 / 共20页
matlab动画制作Word文件下载.docx_第9页
第9页 / 共20页
matlab动画制作Word文件下载.docx_第10页
第10页 / 共20页
matlab动画制作Word文件下载.docx_第11页
第11页 / 共20页
matlab动画制作Word文件下载.docx_第12页
第12页 / 共20页
matlab动画制作Word文件下载.docx_第13页
第13页 / 共20页
matlab动画制作Word文件下载.docx_第14页
第14页 / 共20页
matlab动画制作Word文件下载.docx_第15页
第15页 / 共20页
matlab动画制作Word文件下载.docx_第16页
第16页 / 共20页
matlab动画制作Word文件下载.docx_第17页
第17页 / 共20页
matlab动画制作Word文件下载.docx_第18页
第18页 / 共20页
matlab动画制作Word文件下载.docx_第19页
第19页 / 共20页
matlab动画制作Word文件下载.docx_第20页
第20页 / 共20页
亲,该文档总共20页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

matlab动画制作Word文件下载.docx

《matlab动画制作Word文件下载.docx》由会员分享,可在线阅读,更多相关《matlab动画制作Word文件下载.docx(20页珍藏版)》请在冰点文库上搜索。

matlab动画制作Word文件下载.docx

x1=cos(t1);

y1=sin(t1);

z1=-t1;

t2=(0:

10)/10;

x2=x1(end)*(1-t2);

y2=y1(end)*(1-t2);

z2=z1(end)*ones(size(x2));

t3=t2;

z3=(1-t3)*z1(end);

x3=zeros(size(z3));

y3=x3;

t4=t2;

x4=t4;

y4=zeros(size(x4));

z4=y4;

x=[x1x2x3x4];

y=[y1y2y3y4];

z=[z1z2z3z4];

h=figure('

numbertitle'

'

off'

name'

擦除动画演示(运动的小球)——Matlabsky'

);

plot3(x,y,z,'

b'

axisoff

%绘制红点

h=line('

Color'

[100],'

Marker'

.'

MarkerSize'

40,'

EraseMode'

xor'

%擦除模式设为xor

n=length(x);

i=1;

j=1;

%循环改变坐标,表现为小球运动

while1

if~ishandle(h),return,end

x(i),'

ydata'

y(i),'

zdata'

z(i));

drawnow;

pause(0.0005)%这里设置小球运动速度

i=i+1;

ifnargin==2&

&

nargout==1

if(i==ki&

j==1);

f=getframe(gcf);

end%获取指定的帧,保存到f中

end

ifi>

%判断是否运行了一周,是将i设置为1,并将运行周数j加1

i=1;

j=j+1;

%判断是否到指定的运行周数,是,退出

ifj>

K;

break;

end

%挂摆横梁

%2008.6.9

on'

擦除动画演示(挂摆横梁)——Matlabsky'

%绘制横梁

plot([-0.2;

0.2],[0;

0],'

-k'

linewidth'

20);

%画初始位置的单摆

g=0.98;

%重力加速度,可以调节摆的摆速

l=1;

%摆长

theta0=pi/4;

%初始角度

x0=l*sin(theta0);

%初始x坐标

y0=-l*cos(theta0);

%初始y坐标

axis([-0.75,0.75,-1.25,0]);

axisoff

%创建摆锤

head=line(x0,y0,'

color'

r'

linestyle'

markersize'

40);

%擦除模式为xor

%创建摆杆

body=line([0;

x0],[-0.05;

y0],'

-'

%摆的运动

t=0;

%时间变量

dt=0.01;

%时间增量

while1

t=t+dt;

theta=theta0*cos(sqrt(g/l)*t);

%单摆角度与时间的关系

x=l*sin(theta);

y=-l*cos(theta);

if~ishandle(h),return,end

set(head,'

x,'

y);

%改变擦除对象的坐标数据

set(body,'

[0;

x],'

[-0.05;

y]);

%刷新屏幕

%将下列命令保存到M文件中,直接运行

%Matlab时钟动画演示

%rewritebydynamic

%moreinformationpleasegoto

try

closeall

hfig=figure('

NumberTitle'

ClockAnimationDemo--byMatlabSky'

MenuBar'

none'

theta=linspace(0,6.3,1000);

x1=8*cos(theta);

y1=8*sin(theta);

plot(x1,y1,'

1.4)%绘制外表盘

axisequal

x2=7*cos(theta);

y2=7*sin(theta);

plot(x2,y2,'

y'

3.5)%绘制内表盘

fill(0.4*cos(theta),0.4*sin(theta),'

%绘制指针转轴

axis([-1010-1010])

set(gca,'

position'

[[0.130.050.7750.815]])

title(date,'

fontsize'

18)

fork=1:

12;

xk=9*cos(-2*pi/12*k+pi/2);

yk=9*sin(-2*pi/12*k+pi/2);

plot([xk/9*8xk/9*7],[yk/9*8yk/9*7],'

[0.30.80.9]);

text(xk,yk,num2str(k),'

16,'

[0.90.30.8],'

HorizontalAlignment'

center'

%表盘时刻标度

%计算时针位置

ti=clock;

th=-(ti(4)+ti(5)/60+ti(6)/3600)/12*2*pi+pi/2;

xh3=4.0*cos(th);

yh3=4.0*sin(th);

xh2=xh3/2+0.5*cos(th-pi/2);

yh2=yh3/2+0.5*sin(th-pi/2);

xh4=xh3/2-0.5*cos(th-pi/2);

yh4=yh3/2-0.5*sin(th-pi/2);

hh=fill([0xh2xh3xh40],[0yh2yh3yh40],[0.60.50.3]);

%计算分针位置

tm=-(ti(5)+ti(6)/60)/60*2*pi+pi/2;

xm3=6.0*cos(tm);

ym3=6.0*sin(tm);

xm2=xm3/2+0.5*cos(tm-pi/2);

ym2=ym3/2+0.5*sin(tm-pi/2);

xm4=xm3/2-0.5*cos(tm-pi/2);

ym4=ym3/2-0.5*sin(tm-pi/2);

hm=fill([0xm2xm3xm40],[0ym2ym3ym40],[0.60.50.3]);

%计算秒针位置

ts=-(ti(6))/60*2*pi+pi/2;

hs=plot([07*cos(ts)],[07*sin(ts)],'

w'

2);

set(gcf,'

doublebuffer'

while1;

%每次读取系统时间,并进行运算

set(hh,'

XData'

[0xh2xh3xh40],'

YData'

[0yh2yh3yh40])

set(hm,'

[0xm2xm3xm40],'

[0ym2ym3ym40])

set(hs,'

[07*cos(ts)],'

[07*sin(ts)])

drawnow;

pause(0.09)

catch

'

MatlabSky--打造最优、专业和权威的Matlab技术交流平台!

更多信息参见:

<

ahref="

matlab:

web"

>

/a>

return

%小球绕跑道运动

figure('

MatlabAnimationDemo--bymatlabsky'

prompt={'

请输入速度v:

请输入长度L:

请输入半径r:

};

default={'

5'

10'

2'

v=5;

L=10;

r=2;

p=inputdlg(prompt,'

输入参数'

1,default);

v=str2double(p

(1));

L=str2double(p

(2));

r=str2double(p(3));

ifv<

=0|L<

=0|r<

=0

warndlg('

Matlabsky提醒您:

输入参数必须为整数'

警告'

else

axis([0,2*r+L,0,2*r])

ox1=r;

oy1=r;

ox2=r+L;

oy2=r;

x1=r:

0.015*v:

r+L;

y1=2*r*ones(size(x1));

thita=0:

0.015*v/r:

pi;

x2=sin(thita)*r+ox2;

y2=cos(thita)*r+oy2;

x3=r+L:

-0.015*v:

r;

y3=zeros(size(x3));

x4=-sin(thita)*r+ox1;

y4=-cos(thita)*r+oy1;

x=[x1x2x3x4];

y=[y1y2y3y4];

plot(x,y);

text(0,-2,['

长度L='

num2str(L)'

'

'

半径r='

num2str(r)'

速度v='

num2str(v)]);

axisequal

set(gca,'

Visible'

hm=line(r,2*r,'

red'

marker'

37,'

while1

fori=1:

length(x)

try

set(hm,'

y(i));

pause(0.0003)

drawnow

catch

return

%动态绘制椭圆

clf;

axis([-2,2,-2,2]);

axisequal;

pause

(1);

h=line(NaN,NaN,'

o'

linesty'

t=6*pi*(0:

0.02:

1);

forn=1:

length(t)

2*cos(t(1:

n)),'

sin(t(1:

n)));

pause(0.05);

%暂停0.05秒

%卫星绕地球旋转演示动画——Matlabsky

%2008.12.23

卫星绕地球旋转演示动画——Matlabsky'

%设置标题名字

s1=0:

.01:

2*pi;

holdon;

%建立坐标系

axisoff;

%除掉Axes

r1=10;

%地球到太阳的平均距离

r2=3;

%卫星的轨道半径

w1=1;

%设置地球公转角速度

w2=12;

%设置卫星绕地球公转角速度

%初始时刻

pausetime=.002;

%设置视觉暂留时间

sita1=0;

sita2=0;

%设置开始它们都在水平线上

)%消除抖动

plot(-20,18,'

text(-17,18,'

太阳'

%对太阳进行标识

plot(-20,16,'

text(-17,16,'

地球'

%对地球进行标识

plot(-20,14,'

13);

text(-17,14,'

卫星'

%对卫星进行标识

plot(0,0,'

60);

%画太阳

plot(r1*cos(s1),r1*sin(s1));

%画地球公转轨道

xlim'

[-2020],'

ylim'

[-2020]);

p1=plot(r1*cos(sita1),r1*sin(sita1),'

30);

%画地球初始位置

l1=plot(r1*cos(sita1)+r2*cos(s1),r1*sin(sita1)+r2*sin(s1));

%画卫星绕地球的公转轨道

p2x=r1*cos(sita1)+r2*cos(sita2);

p2y=r1*sin(sita1)+r2*sin(sita2);

p2=plot(p2x,p2y,'

%画卫星的初始位置

orbit=line('

p2x,'

p2y,'

%画卫星的运动轨迹

set(p1,'

r1*cos(sita1),'

r1*sin(sita1));

%设置地球的运动过程

set(l1,'

r1*cos(sita1)+r2*cos(s1),'

r1*sin(sita1)+r2*sin(s1));

%设置卫星绕地球的公转轨道的运动过程

ptempx=r1*cos(sita1)+r2*cos(sita2);

ptempy=r1*sin(sita1)+r2*sin(sita2);

set(p2,'

ptempx,'

ptempy);

%设置卫星的运动过程

p2x=[p2xptempx];

p2y=[p2yptempy];

set(orbit,'

p2y);

%设置卫星运动轨迹的显示过程

sita1=sita1+w1*pausetime;

%地球相对太阳球转过的角度

sita2=sita2+w2*pausetime;

%卫星相对地球转过的角度

pause(pausetime);

%视觉暂停

drawnow%刷新屏幕,重绘

%擦除动画实例——太阳|地球|月亮|卫星,绕转演示动画

%2008.12.6

clear;

clc;

%定义几组变量.分别代表的含义是:

%相对圆心坐标半径最近距离最远距离周期角速度旋转角度

x0=0;

y0=0;

r0=80;

Lmin0=0;

Lmax0=0;

T0=2160;

w0=0*pi/T0;

q0=0;

x1=0;

y1=0;

r1=40;

Lmin1=25;

Lmax1=30;

T1=1080;

w1=pi/T1;

q1=0;

x2=0;

y2=0;

r2=20;

Lmin2=8;

Lmax2=10;

T2=180;

w2=pi/T2;

q2=0;

x3=0;

y3=0;

r3=10;

Lmin3=3;

Lmax3=05;

T3=30;

w3=pi/T3;

q3=0;

%初始化

hh=figure('

太阳|地球|月亮|卫星,绕转演示动画——Matlabsky'

%设置擦除方式

sun=line(0,0,'

r0);

%太阳

earth=line(x0,y0,'

k'

r1);

%地球

moon=line(x1,y1,'

r2);

%月亮

satellite=line(x2,y2,'

g'

norm'

r3);

%卫星

%添加标注

title('

太阳|地球|月亮|卫星'

fontname'

宋体'

9,'

FontWeight'

demi'

black'

text(-20,50,'

——更多精彩参见'

text(-50,50,'

%对太阳进行标识

line(-55,50,'

80);

text(-50,40,'

%对地球进行标识

line(-55,40,'

text(-50,30,'

月亮'

%对月亮进行标识

line(-55,30,'

text(-50,20,'

%对卫星进行标识

line(-55,20,'

10);

%绘制轨道

s1=[0:

2*pi];

line(Lmax1*cos(s1),Lmin1*sin(s1),'

:

%画地球的轨迹,是个椭圆

axis([-60,60,-60,60]);

%调整坐标轴

%开始画图

t=0;

if~ishandle(hh),return,end

q0=t*w0;

q1=t*w1;

q2=t*w2;

q3=t*w3;

t=t+1;

%设置运动规律

ift>

=4320;

t=0;

end%到了一个周期就重置

x0=Lmax0*cos(q1);

y1=Lmin0*sin(q1);

%设置太阳圆心的坐标(在这个程序里,太阳圆心的坐标是不变的,所以可以省略)

x1=x0+Lmax1*cos(q1);

y1=y0+Lmin1*sin(q1);

%设置地球圆心的坐标

x2=x1+Lmax2*cos(q2);

y2=y1+Lmin2*sin(q2);

%设置月亮圆心的坐标

x3=x2+Lmax3*cos(q3);

y3=y2+Lmin3*sin(q3);

%设置卫星圆心的坐标

set(sun,'

x0,'

y0);

%画太阳

set(earth

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 考试认证 > 公务员考试

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2