How to save datetime values in an array?
134 次查看(过去 30 天)
显示 更早的评论
Hi I am picking datetime value that is in this format
05-Feb-2015 18:02:47 05-Feb-2015 18:02:51 05-Feb-2015 18:02:55
I want to save it in an array so that later I can plot it. I am getting error to convert from datetime to double. What should i do?
6 个评论
Guillaume
2015-6-25
Clarification, the d1 example is nothing to do with me and the OP (Venky) appears to confuse the char type with the datetime time. He (she?) also does not seem to understand string to numeric conversion.
回答(1 个)
Guillaume
2015-6-24
编辑:Guillaume
2015-6-24
If you're getting this error it's because you're trying to put a datetime object in a preinitialised array (possibly with zeros ?) of double. I presume you preinitialise the array, because the datetime objects are created / obtained in a loop.
You can't put datetime objects in a preinitialised array of double (you can only put doubles in there). The datetimes have to go in a preinitialised array of datetime. One simple way of initialising such an array:
darr = datetime(zeros(10,1), 0, 0); %a 10x1 array of datetime
Note that there will be a simpler way of doing this in the next version of matlab.
5 个评论
Guillaume
2015-6-26
A matrix can store data of only one type. So you can't put datetimes and float together, or float and integer together, or float and string together.
There are various kind of heterogeneous containers available in matlab, the simplest being cell arrays and tables
f1 = {d e}; %cell array
f2 = table(d, e, 'VariableNames', {'index', 'date'}); %table
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!