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