无法打印当前图形

Failing to print current figure

这里尝试通过将帧生成为图形序列来创建简单动画,并以 .png 格式保存1:

clc
clear
close all

% don't display plot : produces error.
%set(0, 'defaultfigurevisible', 'off');

% number of frames.
N = 2; 

% generate data sets.
x = linspace(0, 6 * pi, 1000);
y = sin(x);

% run animation.
for i = 1 : N

  % create figure.
  clf
  % hold on % produces error.
  plot(x, y, x(i), y(i), 'ro')
  % plot(x(i), y(i), 'ro') 

  grid on
  axis tight

  title( sprintf( 'Sine Wave at (%f, %f)', x(i), y(i) ) )
  xlabel('x')
  ylabel('y')

  drawnow 

  % create frame name: fr00001.png, etc. 
  framename = sprintf('output/fr%05d.png', i);

  % save current figure in file: output.
  print(framename);

end  

然而,我唯一得到的是:

Mesa warning: couldn't open dxtn.dll, software DXTn compression/decompression unavailable
GL2PS error: Incorrect viewport (x=0, y=240883432, width=0, height=240885832)
error: gl2ps_renderer::draw: gl2psBeginPage returned GL2PS_ERROR
error: called from
opengl_print at line 172 column 7
print at line 519 column 14
sinewave at line 48 column 3

如有任何建议,我们将不胜感激。

注意:注释行是故意留下的。


1.稍后在编码器的帮助下以 .avi 格式拼接成电影。

在 Windows 10

的 Octave-4.2.1 上执行

1 的帮助是使用 print() 和图形的图形句柄并定义文件名 (.png),包括绝对路径它们将被存储的目录。注意子目录用 \ 而不是 / 表示,此外,它需要一个额外的 \ 转义字符才有效。然后是下面的代码:

N = 1000;
x = linspace(0, 6*pi, N);
y = sin(x);

abspath = 'D:\...\Project\output\';
fh = figure();

for i = 1 : N  
  clf
  hold on  
  plot(x, y);
  plot(x(i), y(i), 'ro')
  grid on
  axis tight
  title( sprintf( 'Sine Wave at (%f, %f)', x(i), y(i) ) )
  xlabel('x')
  ylabel('y')
  drawnow

  framename = sprintf('%sfr%04d.png', abspath, i);
  print(fh, framename);
end  

产生 1000 帧,当 2 拼接在一起时得到:


1。几百个plot之后还是莫名其妙的崩溃了

2。使用 imagemagick 的命令将前 100 个 .png 文件转换为 .gifmagick convert -delay 10 -loop 0 *png output.gif.