Txt读取参数


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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值