필터 지우기
필터 지우기

Write a sentence in multiple files

조회 수: 2 (최근 30일)
JAMMI ASHOK
JAMMI ASHOK 2021년 8월 8일
댓글: JAMMI ASHOK 2021년 8월 8일
Hi,
I have a many '.txt' files in a folder.
a.txt, b.txt, c.txt ......
Now I want to open each one of them one by one and print the following sentence in the 5th line from the beginning of each one them including the file name.
The sentence is :
a.txt > "I am in a file"
b.txt > "I am in b file"
these line should be printed on the 5th line from the file starting.
Can you please tell me the procedure

채택된 답변

Image Analyst
Image Analyst 2021년 8월 8일
And this snippet:
% Open the file for reading in text mode.
fileID = fopen(fullFileName, 'rt');
% Read the first line of the file.
textLine = fgetl(fileID);
lineCounter = 1;
while ischar(textLine)
% Print out what line we're operating on.
fprintf('%s\n', textLine);
% Read the next line.
textLine = fgetl(fileID);
lineCounter = lineCounter + 1;
end
% All done reading all lines, so close the file.
fclose(fileID);
Good luck.
  댓글 수: 3
Image Analyst
Image Analyst 2021년 8월 8일
To find out what functions a file requires, you can do
[requiredFileList, toolboxList] = matlab.codetools.requiredFilesAndProducts(fullFileName);
Attached is my function wrapper for it.
JAMMI ASHOK
JAMMI ASHOK 2021년 8월 8일
Thank you.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Standard File Formats에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by