Reading csv file and formating timestamp
Show older comments
I am starting with a csv file with 3 columns and over 3500 lines. It looks like the following:
[2011/111/23:25:42.720108,CDTime_Time_Text,-000:09:00:00.000]
[2011/111/23:25:45.167073,GN2 Initial State, 0]
[2011/111/23:25:45.184703,LN2 DCVNC-3009 State, 0]
This is: [timestamp, identifier, timestamp -or- data]
I want to read the file into Matlab and: a) timestamp - remove the year and day and keep the hr:min:sec.sec. eventually convert this to seconds b) keep the identifier as a string c) keep the timestamp or data as integer
I have tried the textread but am having problems getting the timestamp converted into seconds. here is something that I tried: [main.utc, main.fd, main.data]= textread(rawdatafile, '%s %s %s', 'delimiter', ',')
Any help would be appreciated!
Thanks, Aaron
Accepted Answer
More Answers (1)
Oleg Komarov
on 7 May 2011
Textscan solution: import skipping the non relevant parts
fid = fopen('C:\Users\Oleg\Desktop\test.txt');
fmt = '%*f/%*f/%f:%f:%f%s%s';
opt = {'Delimiter',',','CollectOutput',1};
data = textscan(fid,fmt,opt{:});
fid = fclose(fid);
Point a)
secs = data{1}*[3600; 60; 1];
Point b)
data{2}(:,1)
Point c) - not clear
Categories
Find more on Logical 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!