qlineseries绘制动态曲线_matlab 怎么动态画曲线

本文展示了如何利用Matlab制作动态gif,以显示三维欧拉公式的增长过程。通过示例代码,详细解释了如何绘制并更新曲线,最终生成包含动态变化的gif图像。
摘要由CSDN通过智能技术生成

展开全部

可以用Matlab制作gif来实现,下面是一个示例代码:%适用于在一幅图中表现给e69da5e887aa62616964757a686964616f31333339666662图过程,即图形的增长过程

%主要用来绘制三维的欧拉公式

clc;clear;clf;close all;

%获得数据

tmax = 4*pi;

t = 0:0.01:tmax;

tmp = exp(1i*t);

x = real(tmp);

y = imag(tmp);

[a,b] = size(x);

y1 = zeros(a,b) ;

x1 = zeros(a,b);

%确定首幅图的样式,并指定标题,坐标轴标题等样式

plot3(x(1,1),t(1,1),y(1,1),'black');

hold on

plot3(x(1,1),t(1,1),y1(1,1),'blue');

plot3(x1(1,1),t(1,1),y(1,1),'r');

axis([-1,1,0,tmax,-1,1])

str = ['$${e^{it}} = \cos t + i\sin t $$',char(13,10)','created

by Lijunjie!'];

title({str},'Interpreter','latex')

xlabel('实轴');

ylabel('时间轴');

zlabel('虚轴');

grid on;

set(gcf,'Position',[0,0,600,600], 'color','w');

set(gca,'ydir','reverse')   %反转坐标轴

%确保图像在采集的过程中包括坐标轴及标题

ax = gca;

ax.Units = 'pixels';

pos = ax.Position;

ti = ax.TightInset;

rect = [-ti(1), -ti(2), pos(3)+ti(1)+ti(3), pos(4)+ti(2)+ti(4)];

%在指定的范围内获得图像文件

frame = getframe(ax,rect);

im=frame2im(frame);

%创建gif文件,指定其样式,写入首帧图像

k = 1;

%用胞元存储采集到的图像,方便后面反转图像用

[I{k},map{k}]=rgb2ind(im,256);

imwrite(I{k},map{k,1},'mygif.gif','gif','Loopcount',Inf,'DelayTime',0.2);

k = k + 1;

%画图并采集到gif中

steptmp = 20;   %每幅图要画的点数

i = steptmp;

while i 

x_1 = x(1,(i-steptmp+1):i+1);

t_1 = t(1,(i-steptmp+1):i+1);

y_1 = y(1,(i-steptmp+1):i+1);

y1_1 = y1(1,(i-steptmp+1):i+1);

x1_1 = x1(1,(i-steptmp+1):i+1);

plot3(x_1,t_1,y_1,'black');

hold on

plot3(x_1,t_1,y1_1,'blue');

plot3(x1_1,t_1,y_1,'r');

%下面是制作gif的主要代码,除了调节间隔时间外,一般不需要改动

ax = gca;

ax.Units = 'pixels';

pos = ax.Position;

ti = ax.TightInset;

rect = [-ti(1), -ti(2), pos(3)+ti(1)+ti(3), pos(4)+ti(2)+ti(4)];

frame = getframe(ax,rect);

im=frame2im(frame);

[I{k},map{k}]=rgb2ind(im,256);

%写入模式为“追加”模式

imwrite(I{k},map{k},'mygif.gif','gif','WriteMode','append','DelayTime',0.1);

k = k + 1;

i = i + steptmp;

end

%将图像按相反的顺序再写入到gif中

for i = (k-1):-1:1

imwrite(I{i},map{i},'mygif.gif','gif','WriteMode','append','DelayTime',0.1);

end

运行完毕后,在Matlab当前的路径下,即可找到一个gif文件:

65487ea56bf798703282a9f59a89f925.gif

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值