My .txt file imports as a character string

1 view (last 30 days)
Hi all,
I'd like to import a text file as a matrix of data. Here's what I have so far:
thefilename = gunzip('ftp://podaac-ftp.jpl.nasa.gov/allData/grace/L2/CSR/RL05/GAC-2_2004001-2004013_0013_UTCSR_0000_0005.gz');
copyfile(char(thefilename),[char(thefilename),'.txt']);
If I double-click on the resultant .txt file, I see that the formatted data begins on line 9, after 8 rows of headers. How can I tell Matlab to import the columns of data from rows 9:end?
Thanks, Chad

Accepted Answer

Walter Roberson
Walter Roberson on 26 Jun 2012
textscan() with the HeaderLines option.
  1 Comment
Chad Greene
Chad Greene on 26 Jun 2012
Brilliant! Until now I had a hard time finding the data after using textscan. When I'd use C=textscan(yada_yada), I'd then end up with a character set C, from which I did not now how to extract the data. Now I see I needed to use C{2} for the column two, etc. Here's the solution:
fid = fopen([char(thefilename),'.txt']);
C = textscan(fid,'%s %f %f %f %f %f %f %f %f %s','headerlines',8);
fclose(fid);
Then each column n can be accessed by C{n}. Thanks Walter!

Sign in to comment.

More Answers (0)

Categories

Find more on Data Import and Export 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!