How to use Comma delimiter for this .txt file. I have a file which looks like this. I have to separate them column wise with comma as delimiter. Urgent. Thanks in advance.

2 Ansichten (letzte 30 Tage)
39.984702,116.318417,0,492,39744.1201851852,2008-10-23,02:53:04 39.984683,116.31845,0,492,39744.1202546296,2008-10-23,02:53:10 39.984686,116.318417,0,492,39744.1203125,2008-10-23,02:53:15 39.984688,116.318385,0,492,39744.1203703704,2008-10-23,02:53:20 39.984655,116.318263,0,492,39744.1204282407,2008-10-23,02:53:25

Antworten (1)

Jacob Halbrooks
Jacob Halbrooks am 30 Jan. 2014
Assuming this text is in a file named mydata.txt and you want to read it into MATLAB, you can use TEXTSCAN. In the data, I see each row appears to have 5 numbers followed by a date and a time. In the format specifier then, I'd use %f to capture the numbers and %s for the dates and times. TEXTSCAN also allows you to define the delimiter:
fid = fopen('mydata.txt');
data = textscan(fid,'%f%f%f%f%f%s%s','Delimiter',',');
fclose(fid)
The "data" variable is now a cell array, with a cell for each column:
>> data{1}
ans =
39.9847
39.9847
39.9847
39.9847
39.9847

Kategorien

Mehr zu Text Data Preparation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by