My .txt file imports as a character string

1 Ansicht (letzte 30 Tage)
Chad Greene
Chad Greene am 26 Jun. 2012
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 26 Jun. 2012
textscan() with the HeaderLines option.
  1 Kommentar
Chad Greene
Chad Greene am 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!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Import and Export finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by