Column of dates to vector
2 次查看(过去 30 天)
显示 更早的评论
Hey guys,
I have a table that contains dates that I would like to convert to a column of numbers (a vector), so I can do some further manipulation. When i use the following code: dateNum = datevec(date);
I get the following error:
Error using datevec (line 116)
The input to DATEVEC was not an array of character vectors or strings.
Any assistance would be greatly appreciated.
2 个评论
Steven Lord
2022-11-17
By "contains dates" are you referring to a datetime array or an array of serial date numbers?
What type of manipulation do you want to do? There may be a way to perform that manipulation directly on the datetime array without having to convert to a numeric representation.
What do the numbers you want to generate represent? Number of days since a certain date and time, number of hours, number of minutes, number of seconds, etc.?
回答(1 个)
Narvik
2024-9-4
Hi Kendal,
As per my understanding, you are trying to convert your date strings into a numeric format and filter data for specific years.
The error "The input to DATEVEC was not an array of character vectors or strings" implies that the input "date" is not in expected format. Ensure that the dates are in string format.
dateStrings = {'09/04/2024 12:00:00 AM', ...}; % Example date strings
Then use "datevec" to convert strings into date vectors.
dateVectors = datevec(dateStrings, 'mm/dd/yyyy HH:MM:SS AM');
Refer to the following documentation for more information on "datevec" function:
Hope this helps!
0 个评论
另请参阅
类别
在 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!