フィルターのクリア

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);
  1 件のコメント
Avi
Avi 2018 年 1 月 18 日
Thanks for your help. It works. cheers..!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import and Export についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by