Need to import CSV file with date and time
Ältere Kommentare anzeigen
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!!
4 Kommentare
ashwani gupta
am 19 Feb. 2019
Sir, i am facing same kind of problem importing date. I am not getting any values , instead of it getting NaN at all the entries. Please help to get the year and date from the file.
ashwani gupta
am 19 Feb. 2019
Sir, i am facing same kind of problem importing date. I am not getting any values , instead of it getting NaN at all the entries. Please help to get the year and date from the file.
Geoff Hayes
am 19 Feb. 2019
ashwani - what code have you written to read the data from the file?
Peter Perkins
am 20 Feb. 2019
Adding a new question as a comment to a four-year-old thread is considered bad form. You should start a new thread.
In any case, this file should be easy for readtable in recent versions of MATLAB. At worst, you may need to use detectimportoptions. In that new thread, say what version of MATLAB, exactly what you have done so far, and exactly what result you got.
Akzeptierte Antwort
Weitere Antworten (2)
VISWANATH
am 8 Sep. 2014
0 Stimmen
1 Kommentar
Geoff Hayes
am 8 Sep. 2014
You may not need a for loop. You've changed the input file so I can't test it out like I did before, but since the second column of data corresponds to the date and time information, then try the following
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);
% grab the date and time column
dateAndTimeData = data{2};
% convert to serial
dateAndTimeSerial = datenum(dateAndTimeData(:,1),...
'mm/dd/yyyy HH:MM:SS:FFF');
% set the reference time
refTimeSerial = datenum('01/09/2014 15.13.48','mm/dd/yyyy HH.MM.SS');
% compute the time in minutes from reference
timeInMinsFromRef = (dateAndTimeSerial-refTimeSerial)*24*60
end
Try out the above - it should give the desired result without having to do a loop.
Jayant Singh
am 4 Sep. 2015
0 Stimmen
Dear friends, This seems to be a very helpful place for clarifications.
I have a question regarding textscan. When we use textscan, how can I get all the data in rectangular format? I have tried it. I only get series of columns data{1}, data{2}, and so on. Is it possible to get everything back in rectangular format? Any response is greatly appreciated.
thanks
Kategorien
Mehr zu Dates and Time finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!