例子:处理一文件夹下的所有文件,读取每个文件里的数据并利用相应数据画图,保存每个图片。
代码:
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)%batch 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
代码:
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)%batch 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