数据文件处理

来源:百度文库 编辑:神马文学网 时间:2024/06/03 08:15:55

Matlab数据文件处理小程序

在实验中,处理记录数据文件是经常要做的,而用Matlab来处理是我最推崇的,方便快捷,数据文件格式任意设置,均可处理,如用下面格式保存的数据文本data.txt,用Matlab来处理,用这个小程序做来非常容易,而且处理后得到的图形可直接Copy到各种需要的文件中。

data.txt文件:

......

d+00005.00;v+00001.92;e+00003.08;u-0016;m+1004;t+0286;

d+00005.00;v+00002.06;e+00002.94;u-0041;m+0988;t+0287;

d+00005.00;v+00002.19;e+00002.81;u-0040;m+0947;t+0288;

d+00005.00;v+00002.31;e+00002.69;u-0033;m+0907;t+0289;

d+00005.00;v+00002.39;e+00002.61;u-0024;m+0874;t+0290;

d+00005.00;v+00002.47;e+00002.53;u-0024;m+0850;t+0291;

d+00005.00;v+00002.56;e+00002.44;u-0025;m+0826;t+0292;

d+00005.00;v+00002.61;e+00002.39;u-0016;m+0801;t+0293;

d+00005.00;v+00002.69;e+00002.31;u-0024;m+0785;t+0294;

d+00005.00;v+00002.72;e+00002.28;u-0007;m+0761;t+0295;

.....

 处理函数readprocess

function readprocess(file)

fid=fopen(file,'rt');

if(fid==-1)

   display('File not exist!');

   return;

end

array=[];

while(~feof(fid))

   str=fscanf(fid,'%s',1);

   if(length(str)>10)

        %d+00005.00;v+00002.72;e+00002.28;u-0007;m+0761;t+0295;

        col=sscanf(str,'d%f;v%f;e%f;u%f;m%d;t%d;');

       array=[array col];

   end

end

fclose(fid);

dhead=array(1,:);

head=array(2,:);

'r:',t,head,'b-');

运行环境,Matlab5X

使用方法:readprocess data.txt

你可以根据需要处理。