How to read data from text file (combine text and datal)

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

Answers (2)

FileName = 'PhantomASTM20180731000006.txt';
FID = fopen(FileName, 'r');
Data = textscan(FID, '%f%f%f', 'HeaderLines', 32, 'CollectOutput', true);
fclose(FID);
Data = Data{1};
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

This solution doesn't really differ from OCDER's; the two were posted at the same time.

Sign in to comment.

Categories

Find more on Data Import and Analysis in Help Center and File Exchange

Asked:

on 1 Aug 2018

Commented:

on 1 Aug 2018

Community Treasure Hunt

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

Start Hunting!