Filter löschen
Filter löschen

Editing a .m file

2 Ansichten (letzte 30 Tage)
JR
JR am 21 Nov. 2018
Beantwortet: Walter Roberson am 21 Nov. 2018
I have the following code
a='Name: John Cena';
fprintf('%s\n', a)
b='ID: 500';
fprintf('%s\n', b)
c='Degree: B.S.';
fprintf('%s\n', c)
d='Subject: Physics';
fprintf('%s\n', d)
e='Salary: 1000000.59';
fprintf('%s\n', e)
f='Age: 41';
fprintf('%s\n', f)
which gives this result
Name: John Cena
ID: 500
Degree: B.S.
Subject: Physics
Salary: 1000000.59
Age: 41
I need to delete a couple aspects of this and add new ones. How do I do this? Do I need to use fgetl?
  1 Kommentar
Image Analyst
Image Analyst am 21 Nov. 2018
What is an "aspect"? Why don't you just comment out the lines of code you don't want and add in new lines of code to do what you want? I don't see why fgetl() is needed in this program. It's used for getting strings out of files, not for what you're doing, which is all in code.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 21 Nov. 2018
you should consider fileread to read the file as aa character vector . Then you can regexprep if you want to work in terms of text patterns . If you prefer to work on aa line basis then instead of regexprep then regexp(S,'\r?\n','split') to break into a cell array of character vectorss that can be indexed .

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by