Need to import CSV file with date and time
显示 更早的评论
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 个评论
ashwani gupta
2019-2-19
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
2019-2-19
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
2019-2-19
ashwani - what code have you written to read the data from the file?
Peter Perkins
2019-2-20
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.
采纳的回答
更多回答(2 个)
VISWANATH
2014-9-8
0 个投票
1 个评论
Geoff Hayes
2014-9-8
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
2015-9-4
0 个投票
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
类别
在 帮助中心 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!