Filter löschen
Filter löschen

How to change code in scripts using command

14 Ansichten (letzte 30 Tage)
Joyce Taylor
Joyce Taylor am 30 Apr. 2016
Kommentiert: Deep Manvar am 22 Dez. 2020
Certainly ,i could change it manually.But using command along with Conditional statements can achieve this process automatically.

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 30 Apr. 2016
Bearbeitet: Azzi Abdelmalek am 30 Apr. 2016
You can read the content of your m-file
fid=fopen('file.m')
line=fgetl(fid);
k=1;
while ischar(line)
out{k,1}=line;
line=fgetl(fid);
k=k+1;
end
fclose(fid)
Insert what you want in the cell array out. Then save it in the original file
fid= fopen('file.m','w')
for k=1:numel(out)
fprintf(fid,'%s\n',out{k})
end
fclose(fid)

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements 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!

Translated by