How do I check if the specific line in a text file is empty or not?

조회 수: 11 (최근 30일)
Avi
Avi 2018년 1월 11일
댓글: Avi 2018년 1월 18일
I have two text file. I want to read either one of them, First file has numbers from line 5 and the second from 7. I have to determine which file to read based on the starting of numbers. Thanks in advance cheers!!

채택된 답변

Harish Ramachandran
Harish Ramachandran 2018년 1월 17일
A trivial implementation would be to open the file, check if the numbers exist till the 6th line and display which file is being read.
file = fopen('sample.txt');
line = fgetl(file);
for i=1:6
if any(line >= '0' & line <= '9')
disp("The fifth line contains numbers => first file")
else
disp("The fifth line does not contain numbers => second file")
line = fgetl(file);
end
fclose(file);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by