필터 지우기
필터 지우기

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 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