I want to read text file with string in the middle of file

조회 수: 6 (최근 30일)
darush eghbali
darush eghbali 2017년 6월 25일
편집: Jan 2017년 6월 25일
I want to read the number in separate column in the text file. How can I do that ? I want to skip the first line and read file until line 200 and skip line 201 and read 202 ... and do this until the end of the file.I will be thankful if anyone can help.

답변 (1개)

Jan
Jan 2017년 6월 25일
편집: Jan 2017년 6월 25일
nColumn = 3;
nLine = 200;
fid = fopen(FileName, 'r');
if fid == -1, error('Cannot open file: %s', FileName); end
DataC = {};
while ~feof(fid)
fgetl(fid); % Skip one line;
try
DataC{end+1} = sscanf(fid, '%g', [nColumn, nLine]).';
catch
end
end
fclose(fid);
Data = cat(1, DataC{:});

카테고리

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

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by