How to read data from text file (combine text and datal)
15 views (last 30 days)
Show older comments
Is there a way to read data from a specific section of a text file? I am trying to import the data in line 33 (of the attached document).
Thanks in advance
0 Comments
Answers (2)
OCDER
on 1 Aug 2018
FileName = 'PhantomASTM20180731000006.txt';
FID = fopen(FileName, 'r');
Data = textscan(FID, '%f%f%f', 'HeaderLines', 32, 'CollectOutput', true);
fclose(FID);
Data = Data{1};
0 Comments
Adam Danz
on 1 Aug 2018
After opening the file and specifying the line number to be read, use textscan() to read that line and then close the file.
fid=fopen(fullfile('C:\Users\name\Desktop', 'PhantomASTM20180731000006.txt'));
linenum = 33;
C = textscan(fid,'%s',1,'delimiter','\n', 'headerlines',linenum-1);
fclose(fid);
1 Comment
Adam Danz
on 1 Aug 2018
This solution doesn't really differ from OCDER's; the two were posted at the same time.
See Also
Categories
Find more on Data Import and Analysis 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!