Editing a .m file

1 visualizzazione (ultimi 30 giorni)
JR
JR il 21 Nov 2018
Risposto: Walter Roberson il 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 Commento
Image Analyst
Image Analyst il 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.

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 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 .

Categorie

Scopri di più su Software Development Tools in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by