필터 지우기
필터 지우기

Editing a .m file

조회 수: 2 (최근 30일)
JR
JR 2018년 11월 21일
답변: Walter Roberson 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 .

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by