
动画不是这样做的。
参照你的代码,做了一个简单的例子,供参考:
function zddx=01;
x=1:dx:10;
N=length(x);
y=ones(1,round(N/4));
y(round(N/4)+1:N)=-05ones(1,round(3N/4));
y1=integral(y,dx);
y2=integral(y1,dx);
subplot 311
h1=plot(x(1),y(1));
axis([1,10,-1,15])
subplot 312
h2=plot(x(1),y1(1),'k');
axis([1,10,-1,3])
subplot 313
h3=plot(x(1),y2(1),'b');
axis([1,10,0,10])
for ii=2:length(x)
set(h1,'x',x(1:ii),'y',y(1:ii))
set(h2,'x',x(1:ii),'y',y1(1:ii))
set(h3,'x',x(1:ii),'y',y2(1:ii))
drawnow
pause(001)
end
function [Iy]=integral(y,dx)
total=0;
Iy = y0;
for i=1:length(y)
total = total + y(i)dx;
Iy(i) = total;
end
把所有代码复制保存成M文件运行即可。有问题再追问吧。
matlab的动画比较笨,不能像flash一样逐个设置每个对象的运动轨迹,只能一帧一帧的画
大体思路是先逐帧用plot一类的画图函数画出来,然后用getframe保存,最后用movie2avi转成avi文件
以前做的一个简单动画的例子
function test_movie(T,J,N,forename)
for ii=1:floor(N/3)
plot(T(ii3-2,:));
h=gca;
set(h,'YLim',[-03,1]);
set(h,'XLim',[1,J]);
%saveas(h,[forename,num2str(ii,'%44d'),'emf'])
M(ii) = getframe;
end
%movie(M);
movie2avi(M,[forename,'avi'],'FPS',4)
disp('over')
使用drawnow命令,如下有个例子:
%擦除方式显示小球运动
speed=4000;
x=linspace(0,2pi,speed);
y=tan(sin(x))-sin(tan(x));
plot(x,y);
n=length(x);
line_handle=line('LineStyle','o','LineWidth',3,'MarkerSize',15,
'EraseMode','normal','MarkerEdgeColor','k','MarkerFaceColor','r');
i=1;
while 1
set(line_handle,'xdata',x(i),'ydata',y(i));
drawnow
i=i+1;
if i>n
i=1;
end
end
%这段程序有个问题在于关闭会报错,使用try语句即可解决
如果是录制使用moviein指令
如下有个例子
%利用**方式显示动画
[x,y,z]=peaks(30);%peaks用来测试三维画图
surf(x,y,z);
m=moviein(15);
axis off
colormap(cool)
shading interp%设置阴影效果
for i=1:15
view(-45+15(i-1),30+10(i-1))
m(:, i)=getframe;%抓取画面值并加载到绘图窗口的画面矩阵中
end
movie(m,2)
两个例子
clc;clear;
x=0;n=40;
%set(gca,'nextplot','replacechildren');
for j=1:n
x(j+1)=x(j)+2pi/n;
y=sin(x);
plot(x,y,'-'),axis([0 2pi -1 1]),grid on
M(j) = getframe;
end
movie(M)
figure
Z = peaks; surf(Z);
axis tight
set(gca,'nextplot','replacechildren');
% Record the movie
for j = 1:20
surf(sin(2pij/20)Z,Z)
F(j) = getframe;
end
% Play the movie ten times
movie(F)
例:
%擦除式显示球运
speed=4000;
x=linspace(0,2pi,speed);
y=tan(sin(x))-sin(tan(x));
plot(x,y);
n=length(x);
line_handle=line('LineStyle','o','LineWidth',3,'MarkerSize',15,
'EraseMode','normal','MarkerEdgeColor','k','MarkerFaceColor','r');
i=1;
while 1
set(line_handle,'xdata',x(i),'ydata',y(i));
drawnow
i=i+1;
if i>n
i=1;
end
end
做如下改动:
(1)将x,y全用x(k),y(k)表示
(2)新生成变量tx,ty
(3)用tx,ty画星形线
程序在附件
结果如下:
以上就是关于matlab动画制作求教全部的内容,包括:matlab动画制作求教、请教用matlab画动画、求助matlab绘制动画命令等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)