【问题标题】:How can I save different plot to different name at one go?如何一次将不同的情节保存到不同的名称?
【发布时间】:2014-08-28 19:43:08
【问题描述】:

其实我有这么多数据。首先,我阅读了我的 txt 数据。

M=dlmread('a02_s01_e02_skeleton.txt', ' ');

M1=M(1:40:end,1)
M2=M(1:40:end,2) 
subplot(2,1,1) 
plot(M1)
grid on
subplot(2,1,2)
plot(M2)
grid on

那么,这个图就是我要保存的A1.jpg

M1=M(3:40:end,1)
M2=M(3:40:end,2)  % here is the difference
subplot(2,1,1) 
plot(M1)
grid on
subplot(2,1,2)
plot(M2)
grid on

为此,我想保存 A2.jpg

最后一张是A20.jpg

我使用 saveas 功能,但他们只是说,

无法创建输出文件'A1.jpg.jpg'

我可以选择保存位置吗?

【问题讨论】:

  • 您使用的saveas 的语法是什么?请发布您正在尝试的确切命令。
  • 我只是尝试使用 saveas 功能。使用其他功能就可以了。

标签: matlab plot save figure subplot


【解决方案1】:

尝试使用getframeimwrite

for ii=1:20
    start = 1 + (ii-1)*2;
    M1 = M( start:40:end, 1 );
    M2 = M( start:40:end, 2 ); 
    subplot(1,2,1); plot( M1 ); grid on;
    subplot(1,2,2); plot( M2 ); grid on;
    % here is where the image is generated using getframe
    frm = getframe( gcf );
    imwrite( frm.cdata, sprintf( './A%d.jpg', ii ) );
end

可以修改imwrite命令来改变目标目录:

imwrite( frm.cdata, fullfile( targetFolderName, sprintf( 'A%d.jpg', ii ) ) );

【讨论】:

  • 我可以推荐将目录保存在 C:\kanje 之类的位置吗?
  • @KanjaePark 只需设置targetFolderName = 'c:\kanje'; 并使用第二个imwriteimwrite( frm.cdata, fullfile( targetFolderName, sprintf( 'A%d.jpg', ii ) ) );
  • 一切顺利。非常感谢
  • 你能帮我解答另一个问题吗?
  • 我在几分钟前发布了它
【解决方案2】:

你可以使用hgexport

myPath = 'Your path here';

for ii=1:20
  plotName = strcat(myPath,strcat('A',num2str(ii))); % Path + Name of the file
  newPlot = figure();
  %% Your different plots
  hgexport(newPlot,plot_name,hgexport('factorystyle'),'Format', 'jpeg');
end;
猜你喜欢
  • 1970-01-01
  • 2021-10-22
  • 2018-11-14
  • 2012-12-31
  • 2020-04-18
  • 2021-09-11
  • 2023-04-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多