I want help to delete parameters from text file with matlab coding
1 回表示 (過去 30 日間)
古いコメントを表示
I have requirement to delete some specific parameters from text file and generate new text file with changes. this should be done with matlab coding.
text file is attached herewith.
Following parameters should be deleted from text file:
- Filter_Reset
- GlobalDefault
- Enable
- High_Threshold
- Low_Threshold
0 件のコメント
採用された回答
Raheel Ejaz
2021 年 3 月 4 日
clear;clc;
fileID = fopen('try.txt','r');
S = textscan(fileID,'%s');
fclose(fileID);
S2=[S{:}];
param={'Filter_Reset','GlobalDefault','Enable','High_Threshold','Low_Threshold'};
param_i=zeros(1,length(param));
for i=1:length(param)
param_i(i)=find(~cellfun(@isempty,strfind(S2,param{1,i})));
S2(param_i(i))=[];
end
delete('try.txt')
fileID=fopen('try.txt','at');
for j=1:length(S2)
fprintf(fileID,'%s\n',S2{j,1});
end
fclose(fileID);
3 件のコメント
Raheel Ejaz
2021 年 3 月 8 日
clear;clc;
fileID = fopen('try.txt','r');
S = textscan(fileID,'%s');
fclose(fileID);
S2=[S{:}];
ter='y';
while strcmpi(ter,'y')
param={input('Parameter to delete: ','s')};
param_i=find(~cellfun(@isempty,strfind(S2,param{1})));
S2(param_i)=[];
ter=input('Do You want to delete more? Press Y to Continue and N to terminate: ','s');
end
delete('try.txt')
fileID=fopen('try.txt','at');
for j=1:length(S2)
fprintf(fileID,'%s\n',S2{j,1});
end
fclose(fileID);
Raheel Ejaz
2021 年 3 月 8 日
You can have input from user in this code.... for second part if you want to delete the value of parameter only, You can get the index number of parameter from this line "param_i=find(~cellfun(@isempty,strfind(S2,param{1})));" then you can remove its value.
e.g(Enable = 1, 'If "Enable" is at index # 20 then "=" would be at index# 21 and "1" would be at index# 22' , then code next line become "S2(param_i+2)=[];") . It will delete only "1"
Hopefully I am able to solve the issue.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で MATLAB Report Generator についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!