Textscan .txt into cell array

1 view (last 30 days)
Tiffany Lee
Tiffany Lee on 22 Oct 2012
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,

Answers (1)

RNTL
RNTL on 25 Nov 2012
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.

Categories

Find more on Data Import and Export in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!