フィルターのクリア

Question on Reading lines from text file.

1 回表示 (過去 30 日間)
John
John 2014 年 12 月 6 日
回答済み: Azzi Abdelmalek 2014 年 12 月 6 日
Hi,
I have the following data in the txt file:
2 34 5 6 7 8
34 56 77 12 3
11 34 55 66 89 1
12 34 55 67 8 1
45 67 8 1 2 14
23 45 1 2 8 9
I want to read my file from third line to 5th line and save it in a matrix say A. That is A should be:
A = 11 34 55 66 89 1
12 34 55 67 8 1
45 67 8 1 2 14
I can do this if I have to read my lines from the start to a specified number of lines using fopen and fgetl ...however, I cant figure out how to do this for the above situation. Please Help!

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 12 月 6 日
fid=fopen('file.txt')
for k=1:2
fgetl(fid);
end
A=zeros(3,6)
for k=1:3
A(k,:)=str2num(fgetl(fid))
end
fclose(fid)

その他の回答 (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