Borrar filtros
Borrar filtros

import data .txt file in matlab

2 visualizaciones (últimos 30 días)
Hernaldo Leyton
Hernaldo Leyton el 22 de Nov. de 2017
Comentada: Hernaldo Leyton el 23 de Nov. de 2017
Hello everyone, I have a problem when trying to open a .txt file this is as follows:
Friday 20th of December 2013 01:43:33 PM
Compound:PM10 emissions_ds_name:edgar_HTAPv2_TRANSPORT(EPA-USA-CAN+MICS+TNO+EDGAR) Year:2010 Month:January
lat lon emission 2010 1 (tons)
-55,5 -68,2 0,0188546
-55,5 -68,1 0,0188546
-55,4 -69,5 0,0188546
-55,4 -69,2 0,0188546
-55,4 -68,9 0,0188546
-55,4 -68,8 0,0188546
-55,4 -68,6 0,131982
I've tried it with the importdata function, but the result is only cell arrays with the data not separated (only one column).
I've tried it with the textscan function:
fid = fopen ('edgar_HTAP_PM10_emi_TRANSPORT_2010_1.txt');
data = textscan (fid, '% f% *% f% *% f');
fclose (fid);
and it only generates me arrays of empty cells.
Does anyone have any idea how to do it please?
I want the latitude, longitude and emissions data to be in separate columns
Thank you very much

Respuesta aceptada

KSSV
KSSV el 23 de Nov. de 2017
fid = fopen('my text file');
S = textscan(fid,'%s','Delimiter','\n','headerlines',3) ;
fclose(fid) ;
data = cell2mat(cellfun(@str2num,S{1},'un',0))
  1 comentario
Hernaldo Leyton
Hernaldo Leyton el 23 de Nov. de 2017
Thanks very much. I solved the problem with your suggested code

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Large Files and Big Data en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by