MATLAB: Need to import CSV file with date and time

csvimportdatetime

Dear all, I am a newbie to MATLAB frequently these days. I need to read time from the attached csv file and convert it into minutes. I had looked at many other questions similar to me but seems i am stuck!!
Scan, Time, Temp(C), Alarm 101 1, 01/09/2014 15:13:47:338, 25.408, 0 2, 01/09/2014 15:13:48:322, 25.373, 0 3, 01/09/2014 15:13:49:322, 25.372, 0 4, 01/09/2014 15:13:50:322, 25.373, 0 5, 01/09/2014 15:13:51:322, 25.368, 0
The time column need to be converted to mins and initial time instant need to be referenced. So i need to know the temperature change in mins. Thanks everybody!!

Best Answer

Use textscan to grab all of the data from file
fid = fopen('Data_LDTT.csv');
if fid>0
% note how we skip the header lines and use the delimiter
data = textscan(fid,'%d %s %f %d','Delimiter',',','HeaderLines',10);
% close the file
fclose(fid);
% do stuff
end
data will be a cell array, with its second column containing all of the date strings of the format
'01/09/2014 15:27:18:322'
You may then want to convert each string into a serial date number using datenum and then subtract from that serial date number, the equivalent for the reference time. For example,
refTime = datenum('01/09/2014 15.13.48','mm/dd/yyyy HH.MM.SS');
curTime = datenum('01/09/2014 15:27:18:322','mm/dd/yyyy HH:MM:SS:FFF');
timeInMins = (curTime-refTime)*24*60
timeInMins =
13.5053667984903
The above assumes that the reference time is from the line
Acquisition Date:,01/09/2014 15.13.48
Since the serial date number is the whole and fractional number of days from a fixed, preset date, then to convert to minutes, we must multiply by 24 (the number of hours in a day) and by 60 (the number of minutes in an hour). The 13.5 minute answer (above) seems reasonable given the two time strings.