Editing a .m file

1 visualización (últimos 30 días)
JR
JR el 21 de Nov. de 2018
Respondida: Walter Roberson el 21 de Nov. de 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 comentario
Image Analyst
Image Analyst el 21 de Nov. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 21 de Nov. de 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 .

Categorías

Más información sobre Software Development Tools en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by