Textscan .txt into cell array

2 次查看(过去 30 天)
Tiffany Lee
Tiffany Lee 2012-10-22
I am having a difficult time reading my .txt file in matlab. I want a 16 column cell array but I only get all my data in 1 column. How do I separate it into columns? I also used 'whitespace' to try to have 'AC Type' as a string but it just stops at AC. Any help is appreciated! thanks!
My data looks like this as a .txt
Timestamp,Latitude,Longitude,Fix,AC Type,AC ID,Runway,Tgt Type,Speed,Flight Level,Altitude,Heading,Track,Airport,X,Y
2011-04-19T00:01:59.000Z,33.63510372,-84.40547777,,,,,,1,,,,3115,KATL,1504,-732,
2011-04-19T00:01:59.000Z,33.5446075,-84.52443676,,,,,,293,112.0,11175,80.5,2827,KATL,-9548,-10770,
2011-04-19T00:01:59.000Z,33.63474397,-84.40776058,,,UNKN,,unknown,6,,1006,352.9,3104,KATL,1292,-772,

回答(1 个)

RNTL
RNTL 2012-11-25
Assume your file is the following myfile.txt:
a,b,c,4.31,AA-BB-CC,3
e,f,g,3.25,DD-EE-FF,5
Then use textscan as
fid = fopen(myfile.txt,'r');
txt = textscan(fid,'%s %s %s %f %s %d','delimiter',',');
fclose(fid);
and you get the required cell array.

类别

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