matlab 读取数据,画图

本文详细介绍使用MATLAB从特定格式文件中提取并处理数据的方法。通过读取文件,识别有效数据,转换ASCII码为数值,并绘制数据图表,实现对复杂数据集的有效解析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


matlab处理数据,需要自己提取出有用的数据,这才是要学的

clear all;

[orig_filename, directory_name]=uigetfile({'*.*'},'Select the data file');
filename=strcat(directory_name,orig_filename);
fid1 = fopen(filename, 'r', 'b');
[tmpdata, data_length] = fread(fid1,'uint8');  %读取里面的数据,将数据保存到tmpdata中

%ASCII码空格是32
%ASCII码0是48
%一行数据32个
%ASCII码.是46
%每四个是一个数据,一行8个数据
len=1;
 for i=1:length(tmpdata)
    if(tmpdata(i)==58)
       if(tmpdata(i+1)==32)
           if(tmpdata(i+2)~=46)%做限制,防止误判
              if(tmpdata(i+3)~=46) %做限制,防止误判
              for j=i+1:i+40
                 if(tmpdata(j)~=32)  %空格不读取
                    a(len)=tmpdata(j);%将有效数据保存到a数组中
                    len=len+1;
                 end
                end
              end
           end
       end
    end    
 end
 
 %转换成字符,将a数组中的ascii码转换成char型数据格式
 for i=1:length(a)
    b(i)=char(a(i)); 
 end
 
%将b数组中数据每四位截取出来 
 cnt=1;
 for i=1:4:length(a)
     temp=1;
     for j=1:4
        ch(cnt,temp)=b(i);%将数组每四位截取出来 ,保存到新的ch数组字符串中
        temp=temp+1;
        i=i+1;
     end
     cnt=cnt+1;
 end
 %将数据高低位交换,得到有效格式,比如是12eb ,变成eb12
 for i=1:length(ch)
   temp1=ch(i,1);
   temp2=ch(i,2);
   th(i,1)=ch(i,3);
   th(i,2)=ch(i,4);
   th(i,3)=temp1;
   th(i,4)=temp2;
 end
b=hex2dec(th);%16进制转换成10进制,字符串也可以转成10进制
t=linspace(0,10,length(th));
plot(t,b);  %画图


将数据放在text中


 
 在处理中,变量格式如下

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值