因此,我有一段matlab代码(如下所示),它绘制几个图形,然后将它们保存为postscript文件(.ps)。下面是一些代码:
for n = 1:6
threeD = figure;
plot3(x(:,1),x(:,2),x(:,3)),grid on;
print (gcf, '-depsc2', strcat('plot',num2str(n),'.ps'));
end然后我们运行shell脚本将postscript文件转换为GIF文件,然后以0.10秒的延迟合并它们。
#!/bin/csh
# convert postscript to gif
foreach i ( plot*.ps )
perl pstogif $i $i.gif
end
# merge gifs in order
./gifmerge -10 `ls plot?.gif; ls plot??.gif; ls plot???.gif` > anim.gif
# change permissions
chmod 644 anim.gif
# now clean up
rm plot*.ps plot*.gif但是我在windows上,我不能运行这个脚本(如果不安装cygwin,我会尽量避免)。有没有别的方法可以用matlab制作gif电影,或者这是唯一的方法?如果这是唯一的方法,有没有替代cygwin方法的方法,或者这是在windows中运行shell脚本的唯一方法?
编辑:
下面是我在下面的示例链接中的尝试:
figure(1)
for n = 1:6
%Formualte a str for the title
str = sprintf('test%d', n);
[t,x]=ode45('test',[0.0:0.01:20],[initial(n,1), initial(n,2), initial(n,3)]);
%2D Plot
twoD = figure;
plot(x(:,1),x(:,2)),grid on;
drawnow
frame = getframe(1);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
name = sprintf('2D%d',n);
xlabel('x1(t)');
ylabel('x2(t)');
title(str);
if n == 1;
imwrite(imind,cm,'Test.gif','gif', 'Loopcount',inf);
else
imwrite(imind,cm,'Test.gif','gif','WriteMode','append');
end
end这只给了我一个带有x和y轴、标题和标签的图,但没有实际的图。那只是一片空地。Here's my gif file
发布于 2014-02-24 22:24:06
在MATLAB中完成所有这些工作:
figure(1);
for n = 1:6
clf;
[t,x] = ode45('test', [0.0:0.01:20], [initial(n,1), initial(n,2), initial(n,3)]);
plot(x(:,1),x(:,2));
grid on;
set(gcf, 'color', 'w');
export_fig test.tif -nocrop -append -a1
end
im2gif('test.tif', '-delay', 0.1);您首先需要从MATLAB文件交换下载export_fig和im2gif。
https://stackoverflow.com/questions/21978507
复制相似问题