I want help to delete parameters from text file with matlab coding
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ashwini More
am 4 Mär. 2021
Kommentiert: Raheel Ejaz
am 8 Mär. 2021
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 Kommentare
Akzeptierte Antwort
Raheel Ejaz
am 4 Mär. 2021
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 Kommentare
Raheel Ejaz
am 8 Mär. 2021
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
am 8 Mär. 2021
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Low-Level File I/O finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!