【发布时间】:2020-02-27 01:40:01
【问题描述】:
我正在尝试将动画保存为动画 GIF。
我的情节类似于下面给定的代码。
我也用动画线创建了它。
问题是:
当我将我的图形定义为 f=figure 或 figure(1) 时,它会正确创建 .gif 文件。
但是,我必须在 MATLAB GUI 轴上绘制一个轴作为给定的图形,而不是使用“figure”命令在单独的屏幕上绘制我的图形。
我尝试过:f=(handles.axes_threeDOF);,但是当我使用此功能时,gif 文件会创建屏幕的不同部分。
你能帮我解决我的问题吗?
numpoints = 500;
x = linspace(0,4*pi,numpoints);
y = square(x);
y2 = 3 +square(x+1);
f = figure
h = animatedline('Color','b','LineWidth',2);
h2 = animatedline('Color','r','LineWidth',2);
grid on;
axis([0,12,-3,+6])
for k = 1:numpoints
addpoints(h,x(k),y(k))
addpoints(h2,x(k),y2(k))
drawnow
% Capture the plot as an image
frame = getframe(f);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
% Write to the GIF File
if k == 1
imwrite(imind,cm,'test.gif','gif', 'Loopcount',inf);
else
imwrite(imind,cm,'test.gif','gif','WriteMode','append');
end
end
但它使用这个函数“f=(handles.axes_threeDOF)”创建给定的below
【问题讨论】:
标签: matlab user-interface plot save gif