I want to read text file with string in the middle of file
조회 수: 6 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (1개)
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{:});
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Import, Export, and Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!