加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

转:matlab批处理保存多个输出图像的方法及例子

(2012-01-08 22:07:39)
标签:

matlab

输出

保存

图片

杂谈

例子:处理一文件夹下的所有文件,读取每个文件里的数据并利用相应数据画图,保存每个图片。
代码:
clc
clear
f_structure=dir('F:\Cruise_data_973_II_200806\Ts0805');%--put all the files of pwd in a structure
for i=3:size(f_structure)�tch process
fname=strcat('F:\Cruise_data_973_II_200806\Ts0805\',f_structure(i).name);
%using strcat to get the filename
data=load(fname);
s=findstr(f_structure(i).name,'.txt');
paths=[pwd,'\'];
plot(data(:,1),data(:,2))
xlabel('depth(m)')
ylabel('salinity(PSU)')
title(['dpeht-salinity figure(',f_structure(i).name(1:s-1),')'])

%saveas(gcf,[paths,f_structure(i).name(1:s-1),'_depht_salinity.jpg'])
print(gcf,'-dpng',[paths,f_structure(i).name(1:s-1),'_depht_salinity.png'])%save the figure

end





[转载] (转)转贴自研学的一个保存多个数据文件的方法,关于路径的设置比较有意思,转过来分享一下
.
q:
我作了个200次的for循环,
每次均需输出一幅图像,有没有自动将图像输出成jpg格式、所有的图片存于一个文件夹中
的办法?
另外每次还输出一个数值,可不可以将200个数值输出到一个excel表中?
谢谢各位!
a:
% matlabwy
for k=1:200;
R=rand(200);
imwrite(R,['Liu',num2str(k),'.jpg']);
r=rand;
d(k)=r;
end
dd=d';
save liu.xls dd -ASCII
q:
谢谢,但是我看了一下,imwrite处理的好像必须是数字矩阵,
因为我处理的需要拟合,我画图时使用了hold on(先画出散点图,再hold on,画出拟合
直线),而且200张图片必须加上各自的标题作为标注,还有格网,这又如何处理呢?可不
可以把Figure中已画好的图像保存成jpg格式呢?

谢谢!
a:
象下面这样就可以了

% 批量保存图片和数据的例子
if ~exist('liu')
mkdir('liu')
end
paths=[pwd,'\liu\'];
for k=1:3;
figure;
R=rand(200);
imshow(R,[]);
axis on
saveas(gcf,[paths,'Liu',num2str(k),'.jpg']);
close
r=rand;
d(k)=r;
end
dd=d';
save liu.xls dd -ASCII
=============================================================================


转载自:http://hi.baidu.com/krishinamurti/blog/item/5ca4e517cfaa880ac93d6ddf.html



保存图片的四种方法:

1 直接从菜单保存,有fig,eps,jpeg,gif,png,bmp等格式。

2 edit------〉copy figure,再粘贴到其他程序。

3 用saveas命令保存图片

4 使用plot函数后紧接着用print函数。

print的三个参数:

(1)图形句柄,如果图形窗口标题栏是“Figure 3”,则句柄就是3.(2)单引号字符串,指定存储格式。

用gcf可以获取当前窗口句柄。

png格式:'-dpng'

jpeg:    '-djpeg',

tiff: '-dtiff'

bmp: '-dbitmap'

(3)文件名。

详细用法请 help print

例:

>> x=-pi:2*pi/300:pi;
>> y=sin(x);
>> plot(x,y);
>> print(gcf,'-dpng','abc.png')   % 保存为png格式的图片。

>> figure(2)            % 新建一个句柄为2的图形窗口。
>> plot(x,cos(x));    % 在句柄为2的图形窗口上画图。
>> grid
>> print(2,'-djpeg','C:\abc.jpeg'); %将句柄为2的图形保存为jpeg/jpg格式的图片,文件名为'C:\abc.jpeg'。

转载自:http://hi.baidu.com/northhujia/blog/item/561bad998cc3620e6f068c6c.html:


 

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有