My .txt file imports as a character string

1 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2012-6-26
textscan() with the HeaderLines option.
  1 个评论
Chad Greene
Chad Greene 2012-6-26
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!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import and Export 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by