楼主试试用streamparticles画动画。
load wind
lims = [10064 11667 1725 2875 -002 686];
[x,y,z,u,v,w] = subvolume(x,y,z,u,v,w,lims);
cav = curl(x,y,z,u,v,w);
wind_speed = sqrt(u^2 + v^2 + w^2);
[sx sy sz] = meshgrid(110,20:5:30,1:5);
verts = stream3(x,y,z,u,v,w,sx,sy,sz,5);
h = streamribbon(verts,x,y,z,cav,wind_speed,2);
set(h,'FaceColor','r',
'EdgeColor',[7 7 7],
'AmbientStrength',6)
axis(volumebounds(x,y,z,wind_speed))
grid on
view(3)
camlight right;
set(gcf,'Renderer','zbuffer'); lighting phong
verts = stream3(x,y,z,u,v,w,sx,sy,sz);
streamparticles(verts,70,'animate',10,'ParticleAlignment','off')
t = 0:pi/100:2pi;
y = exp(sin(t));
h = plot(t,y,'YDataSource','y');
for k = 1:001:10
y = exp(sin(tk));
refreshdata(h,'caller')
drawnow
end
,追问请加分!
要绘制动态数字7,您可以使用MATLAB内置的绘图函数和动画功能。以下是一个示例代码,它使用comet函数绘制数字7,并创建一个动态图形:
创建数字7的坐标点
x = [0 1 1 05 05 08 08 0];
y = [0 0 1 1 05 05 1 1];
% 绘制数字7的初始图形
plot(x, y, 'LineWidth', 2);
% 创建一个comet对象,绘制数字7的动态轨迹
h = comet(x, y);
% 设置comet对象的线宽和颜色
hLineWidth = 2;
hColor = 'r';
% 设置动画帧率和持续时间
fps = 25;
duration = 5;
% 计算动画帧数和每帧之间的时间间隔
nframes = round(fps duration);
dt = 1/fps;
% 更新comet对象的位置,并在每个时间步骤上刷新绘图
for i = 1:nframes
% 计算数字7的新位置
x = x + 005 (rand(size(x)) - 05);
y = y + 005 (rand(size(y)) - 05);
% 更新comet对象的位置
hXData = x;
hYData = y;
% 刷新绘图
drawnow;
% 暂停一段时间
pause(dt);
end
在此示例中,我们首先定义了数字7的坐标点,并使用plot函数绘制了初始图形。然后,我们使用comet函数创建了一个comet对象,并将数字7的坐标点传递给该对象,以便它可以绘制数字7的轨迹。接下来,我们设置了comet对象的线宽和颜色,以使其更易于看到。最后,我们使用一个循环来更新数字7的位置,并在每个时间步骤上刷新绘图,从而创建一个动态数字7的效果。
哦 这个问题吗 如果fps设置为1,觉得还是比较快的话
那么在for循环中加一个pause(05)的语句,05可以自己根据情况设置,你试试下面的代码的效果
%by dynamic
%see also http://wwwmatlabskycom
%2008712
close all
figure('toolbar','none','menubar','none','NumberTitle','off','name','**动画录制——Matlabsky');
axis equal
m=moviein(20,gcf);%在当前窗口下,截取20帧
set(gca,'nextplot','replacechildren','box','off','color','b','xgrid','on')
title('截图当前窗口的20帧动画')
for j=1:20
plot(fft(eye(j+16)))
m(:,j)=getframe(gcf); %截取动画帧,保存到m变量中
pause(02)
end
hh=figure('toolbar','none','menubar','none','NumberTitle','off','name','**动画播放——Matlabsky');
title('将截取的动画播放5遍')
set(gca,{'xtick','ytick','xticklabel','yticklabel'},{[],[],[],[]})
movie(hh,m,1)
系统bug。个人的matlab不显示动画是因系统bug,可以重新启动即可修复。MATLAB是美国MathWorks公司出品的商业数学软件,用于数据分析、无线通信、深度学习、图像处理与计算机视觉、信号处理。
%function cupid %丘比特;
clear all
close all
clc
h1=figure('name','为你专属');
filename='111222333gif';
%% set(gcf,'outerposition',get(0,'screensize'));
axis([-15 15 -2 05]);axis off;set(gcf,'color','black');
n=4;a=320;m=10^(-a);
h11=line(NaN,NaN,'marker','','linesty','-','erasemode','none','color','r');
x1=[];
y1=[];
index=1;
for theta=pi/2:-2pi/222:-3pi/2;
r1=1+cos(theta+pi/2);
x1=[x1;r1cos(theta)];
y1=[y1;r1sin(theta)];
set(h11,'xdata',x1,'ydata',y1);
frame=getframe(gcf);
im=frame2im(frame);
[imind,cm]=rgb2ind(im,256);
if index==1
imwrite(imind,cm,filename,'gif', 'Loopcount',inf,'DelayTime',01);
else
imwrite(imind,cm,filename,'gif','WriteMode','append','DelayTime',001);
end
% pause(m);
index=index+1;
end
pause(1);
fill(x1,y1,'r');axis off;set(gcf,'color','black');
text(-016n,-085,'刘洋','fontsize',n18,'color','b');
title('心形线','fontsize',18,'color','m');disp('love you'); pause(1);x2=[]; y2=[];
h22=line(NaN,NaN,'marker','','linesty','-','erasemode','none','color','b');
for theta=pi/2:-2pi/222:-3pi/2;
r2=1+cos(theta+pi/2);
x2=[x2;r2cos(theta)]; y2=[y2;r2sin(theta)]; set(h22,'xdata',x2,'ydata',y2);
frame=getframe(gcf);
im=frame2im(frame);
[imind,cm]=rgb2ind(im,256);
imwrite(imind,cm,filename,'gif','WriteMode','append','DelayTime',001);
pause(m^19);
end
h2=figure('name','爱的表达');
%% set(gcf,'outerposition',get(0,'screensize'));
fill(x2,y2,'r');text(-058,-07,'我爱你','fontsize',40,'color','b');
text(-017,-11,'刘洋','fontsize',18,'color','k');
title('心形线','fontsize',18,'color','m');
axis off;
set(gcf,'color','black');
pause(1);
x3=[];
y3=[];
h33=line(NaN,NaN,'marker','','linesty','-','erasemode','none','color','b');
for theta=pi/2:-2pi/222:-3pi/2
%999一片真心;
r3=1+cos(theta+pi/2);
x3=[x3;r3cos(theta)];
y3=[y3;r3sin(theta)];
set(h33,'xdata',x3,'ydata',y3);
frame=getframe(gcf);
im=frame2im(frame);
[imind,cm]=rgb2ind(im,256);
imwrite(imind,cm,filename,'gif','WriteMode','append','DelayTime',001);
pause(m^19);
end
你的画图函数surf只画了一帧,用pause停顿一下就好,源程序改成下面的就可以了
M=16;
N=20;
a=1;
h=2/M;
phi=zeros(M+2);
phi_new=zeros(M+2);
for i=1:M+2
x(i)=-05h+(i-1)h; %x-coordinates
y(i)=-05h+(i-1)h; %y-coordinates
end
while a<N+1
for j=2:M+1
for i=2:M+1
phi_new(i,j) = 025 ( phi_new(i,j-1)+phi(i,j+1)+phi(i+1,j)+phi_new(i-1,j) ) +
025 h^2 (2picos(05piy(j)^3) (sin(pix(i)^2) +
2picos(pix(i)^2)) + 075 piy(j)cos(pix(i)^2)
(4sin(05piy(j)^3) + 3piy(j)^3cos(05piy(j)^3)));
end
end
surf(x,y,phi);
pause(02)
phi=phi_new;
a=a+1;
end
grid on
欢迎分享,转载请注明来源:表白网
评论列表(0条)