필터 지우기
필터 지우기

Read fixed number of numbers from text file

조회 수: 2 (최근 30일)
Brahim Aboumouadine
Brahim Aboumouadine 2021년 1월 5일
댓글: Brahim Aboumouadine 2021년 1월 5일
i have this matrix bellow save in a text file called test.txt
1 2 3 ...... ......100
101 102 ...... ..200
...........................
901 902 .......1000
i want to read only the first 500 numbers from it . how to do it ?
thanks in advance

채택된 답변

Jeremy Hughes
Jeremy Hughes 2021년 1월 5일
편집: Jeremy Hughes 2021년 1월 5일
I assume the dots are meant as ellipses and not literally dots in the file. If so, you can use textscan pretty effectively here.
fid = fopen(filename);
d = textscan(fid,'%f',500);
d = d{1};
fclose(fid);
And if there are literally dots,
d = textscan(fid,'%f',500,'Whitespace',' .');

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by