引用
damao 的 matlab成批画图
实验采集了几百组数据,一个个画有点麻烦,今天编了个成批画图的程序,并能保存!
源程序如下:
function plot_xt_psd24
% 生成批图
% damao_pq@163.com
%2007/4/21
f24=[5 6 7 8 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 28 29 30
13 15 14 16 17 18 19 20 21 22 23 24 37 39 40 38 41 42 43 44 45 46 47 48];
path='D:\Program Files\MATLAB\R2006a\work\tx_psd\fd24\data_deal_66\';
i=1;
while i<25
infile=['fd_24_66_',num2str(f24(1,i))];
gongkuang_1=infile(1:2);
if strcmp(gongkuang_1,'fd')
gongkuang='发电';
else
gongkuang='抽水';
end
shuiwei=infile(7:8);
cedian=f24(2,i);
loadfile=[path,infile,'.txt'];
if exist(loadfile)
data=load(loadfile);
[m,n]=size(data);
t=data(:,1);
x=data(:,2);
mean_x=mean(x);
sigma_2=var(x);
outdata(i,:)=[f24(1,i),f24(2,i),sigma_2];
y=x-mean_x;
figure(1)
plot(t,x)
set(gca,'xLim',[min(t),max(t)]);
xlabel('s');
ylabel('\mu\epsilon');
title(['时域波形图(工况:',gongkuang,',水位:',shuiwei,',测点:',num2str(cedian),')']);
x_text=mean(t)-(max(t)-min(t))*0.1;
y_text=min(x);
text(x_text,y_text,['x^-=',num2str(mean_x),' \sigma^2=',num2str(sigma_2)]);
outfile=[num2str(f24(2,i)),infile,'_'];
saveas(gcf,[path,outfile,'t-x.emf']);
close
t=0:1/fs:x(length(x));
nfft=256;
window=hanning(256);
noverlap=128;
dflag='none';
zz=psd(y,nfft,fs,window,noverlap,dflag);
[zz,f]=psd(y,nfft,fs,window,noverlap,dflag);
figure(2)
plot(f,zz)
xlabel('f (Hz)');
ylabel('Power Spectrum Magnitude (\mu\epsilon^2/Hz)');
y_text=(max(zz)-min(zz))*0.75+min(zz);
x_text=(max(f)-min(f))*0.65+min(f);
title(['功率谱密度图(工况:',gongkuang,',水位:',shuiwei,',测点:',num2str(cedian),')']);
text(x_text,y_text,['\sigma_\epsilon=',num2str(sqrt(sigma_2)),'\times10^{-6}']);
saveas(gcf,[path,outfile,'zpsd.emf']);
close
end
i=i+1;
end
save([path,'outdata.txt'],'outdata','-ascii');