path_wind='C:\Users\NO1\Desktop\分析配置参数.txt';
fid = fopen(path_wind);
Mct_command=textscan(fid,'%s','delimiter','\n');
Mct_command=Mct_command{1};
%删除注释
for i=1:size(Mct_command)
text1=char(Mct_command(i));
locate=find(text1=='%');
if ~isempty(locate)
Mct_command(i)={''};
end
end
%筛选关键字命令,即*号的位置
[row,~]=size(Mct_command);
command_row=[];
for i=1:row
text1=char(Mct_command(i));
locate=find(text1=='*');
if ~isempty(locate)
command_row=[command_row,i];
end
end
command_num=length(command_row); %判断有多少个命令,依次读取关键字
for i=1:command_num-1
Sigle_command = Mct_command(command_row(i):command_row(i+1)-1,:); %单个命令的所有内容
rownum = size(Sigle_command,1);
command = char(Sigle_command(1,:)); %单个命令所有内容开头是命令
switch command
%依次读取命令
case '*data_wind_path'
%**********************************************************
%风数据读取
%**********************************************************
data_wind_path = [];
command_content = char(Sigle_command(2:rownum));
for j = 1:rownum-1
text = command_content(j,:);
text = strtrim(text);
if ~isempty(text)
data_wind_path = text';
end
end
case '*AnalystParam'
%**********************************************************
%风参数读取
%**********************************************************
wind_AnalystParam = [];
command_content = char(Sigle_command(2:rownum));
for j = 1:rownum-1
text = command_content(j,:);
text = strtrim(text);
if ~isempty(text)
text_x = textscan(text,'%s','delimiter',{',',' '}); %逗号空格分割符号
text_x = str2double(strtrim(text_x{1}));
text_x=rmmissing(text_x);
wind_AnalystParam0 = text_x';
wind_AnalystParam = [wind_AnalystParam;wind_AnalystParam0]; %防止写到了第二行
end
end
end
end
Txt读取参数
最新推荐文章于 2023-03-05 22:12:29 发布