如何在 Matlab 中使用带有循环的打印命令

How to use print command with loops in Matlab

到目前为止,我已经查找过这个关于在 Matlab 中打印图形的简单问题,但没有成功。我有一个这种类型的 for 循环:

N = 5;
for sim = 1:10
  X = randn(sim,N);
  X = mean(X);

  figure;
  plot(X);
  print -depsc X;
end

我想为每个模拟打印并保存一张新图,并自动命名,例如,X1 for sim = 1,X2 for sim = 2,X3 for sim = 3,等等。我如何这样做?

试试这个:

N = 5;
for sim = 1:10
  X = randn(sim,N);
  X = mean(X);

  hFig = figure;
  plot(X);

  % create filename and print to eps
  filename = strcat('X',num2str(sim));
  print(hFig,filename,'-depsc');
end

希望对您有所帮助!