import data .txt file in matlab

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

采纳的回答

KSSV
KSSV 2017-11-23
fid = fopen('my text file');
S = textscan(fid,'%s','Delimiter','\n','headerlines',3) ;
fclose(fid) ;
data = cell2mat(cellfun(@str2num,S{1},'un',0))

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Large Files and Big Data 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by