Editing a .m file

3 次查看(过去 30 天)
JR
JR 2018-11-21
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 个评论
Image Analyst
Image Analyst 2018-11-21
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.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2018-11-21
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