Textscan .txt into cell array

조회 수: 4 (최근 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에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by