0

In MATLAB, I'm trying to plot a series of plots in a loop with the following data:

    x1 = [ 1 2 3 4 5]
    y1 = [ 1 1 1 1 1]
    x2 = [ 1 2 3 4 5]
    y2 = [ 2 2 2 2 2]
    x3 = [ 1 2 3 4 5]
    y3 = [ 2 2 2 2 2]

    plot(x,y)
    title('First Plot')

THEN suppress the output and save all plots to a folder,

with the each file displaying the title names:

  First Plot
  Second Plot
  Third Plot
4

1 回答 1

1

对于将绘图保存到文件,使用标题名称,您可以使用以下内容

    graphTitle='first plot';
    hold on
    h=figure(1);
    title('first plot');
    hold off
    fileName=strcat('path to save',graphTitle,'.jpg');
    print(h,'-djpeg',fileName); 

如果您需要创建和保存大量文件,请创建一个文件名向量,其大小与您需要绘制的向量数量(或矩阵的维度)相同。看看使用当前文件名的索引创建一个句柄并执行上述操作,您应该能够打印您需要的标题等。

当您使用上面的代码时,所有的图都在屏幕上可见,然后打印到文件中。

于 2013-05-16T14:08:16.957 回答