matlab读取txt指定位置的信息

matlab读取txt指定位置的信息

path_wind='分析配置参数-涡振.txt';                  
fid=fopen(path_wind);                       %打开文件
Mct_command=textscan(fid,'%s','Delimiter','\n');    %按照一定格式读取fid文件
Mct_command=Mct_command{1,1};            %获取文件内容       
fclose(fid);                             %关闭文件   
%删除注释字段
for i=1:size(Mct_command)
    text1=char(Mct_command(i));          %读取第i个元胞   
    locate=find(text1=='%');             %判断第i个元胞是否%
    if ~isempty(locate)
        Mct_command(i)={''};            %如果含有%赋值为空
    end
end
%删除空元胞数组
Mct_command(cellfun(@isempty,Mct_command))=[];
%筛选关键字命令,即*号的位置
command_row=[];
for i=1:size(Mct_command,1)
    text1=char(Mct_command(i));
    locate=find(text1=='*');        %查找是否含有*
    if ~isempty(locate)
        command_row=[command_row,i];
    end
end
%读取Monitor_unit_ID
        for j=2:command_row(2)-1
             Monitor_unit_ID0{j,1}=Mct_command{j};
        end
        Monitor_unit_ID0(cellfun(@isempty,Monitor_unit_ID0))=[];
        Monitor_unit_ID=cell2mat(Monitor_unit_ID0);   
%读取Senior_ID
        for j=command_row(2)+1:command_row(3)-1
             Senior_ID0{j,1}=Mct_command{j};
        end
        Senior_ID0(cellfun(@isempty,Senior_ID0))=[];
    Senior_ID=cell2mat(Senior_ID0); 
 %读取Analysis_time
        for j=command_row(3)+1:command_row(4)-1
             Analysis_time0{j,1}=Mct_command{j};
        end
        Analysis_time0(cellfun(@isempty,Analysis_time0))=[];
        text=Analysis_time0{1,1};
        text=textscan(text,'%f','Delimiter',',');
        Analysis_time=cell2mat(text);
 %读取bridge_location
        for j=command_row(4)+1:command_row(5)-1
             bridge_location0{j,1}=Mct_command{j};
        end
        bridge_location0(cellfun(@isempty,bridge_location0))=[];
        text=bridge_location0{1,1};
        text=textscan(text,'%f','Delimiter',',');
        bridge_location=cell2mat(text)
 %读取ECC_parameter
        for j=command_row(5)+1:command_row(6)-1
             ECC_parameter0{j,1}=Mct_command{j};
        end 
        ECC_parameter0(cellfun(@isempty,ECC_parameter0))=[];
        text=ECC_parameter0{1,1};
        text=textscan(text,'%f','Delimiter',',');
        ECC_parameter=cell2mat(text)
 %读取Warning_value
        for j=command_row(6)+1:command_row(7)-1
             Warning_value0{j,1}=Mct_command{j};
        end
        Warning_value0(cellfun(@isempty,Warning_value0))=[];
        Warning_value=[];
        for i=1:size(Warning_value0,1)
            text=Warning_value0{i,1};
            text=textscan(text,'%f','Delimiter',',');
            Warning_value(i,:)=cell2mat(text)
        end
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值