I want to read text file with string in the middle of file
5 views (last 30 days)
Show older comments
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 Comments
Answers (1)
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{:});
0 Comments
See Also
Categories
Find more on Import, Export, and Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!