My .txt file imports as a character string

1 visualización (últimos 30 días)
Chad Greene
Chad Greene el 26 de Jun. de 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

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Import and Export en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by