How to read a specific row of data using Textscan

9 views (last 30 days)
Hello,
I am trying to use textscan to import a specific row of data from an ascii file. The data in the ascii file is organized as such:
I would only like to import the column headers in row 12, but only columns 2-11 (columns B-K). Below is the code I have started, but I am getting confused on how to use textscan to get the specific row of data I want. Any help would be appreciated.
fid = fopen('filelocation');
if fid == -1
disp('Error, check file location')
else
c = textscan(fid,'%s %s %s');
end
fclose(fid);

Accepted Answer

Ameer Hamza
Ameer Hamza on 15 Apr 2020
Edited: Ameer Hamza on 15 Apr 2020
Try this. See the documentation of the textscan to understand these statements.
f = fopen('test.txt');
columns = textscan(f, '%s', 12, 'HeaderLines', 11);
columns = columns{1}(2:11);
fclose(f);
  2 Comments
Shelby_P
Shelby_P on 15 Apr 2020
Hi Ameer,
This work perfectly! Thank you so much for the help, it's much appreciated.

Sign in to comment.

More Answers (0)

Categories

Find more on Large Files and Big Data 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!