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

5 views (last 30 days)
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.

Answers (1)

Jan
Jan on 25 Jun 2017
Edited: Jan on 25 Jun 2017
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{:});

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!