inputting dates in format dd/mm/yyyy (or editing a cell array or similar strings without loop)
1 次查看(过去 30 天)
显示 更早的评论
I have a series of csv files which has date tagged to a time period. My matlab scripts does various calculations to the data and then outputs it into an excel file.
My problem is the dates are in the format "dd/mm/yy HH:MM"
I don't do any manipulation with the data so my original plan was to just keep it as a sting but as the dates go beyond 2030 excel converts the dates to 1930.
Using datestr to convert to a date and then converting back into texts doesn't work as the date is not an acceptable format.
The only solution I can think of is both inelegant and slow. Is there a way of doing this without a loop.
for count1 = 1:numel(dates) dates{count1} = strcat(dates{count1}(1:6),'20',dates{count1}(7:16)) end
Note:
dates is x 1 cell in format. (example date is in European format i.e. 1st April 2015) '01/04/15 00:00'
'01/04/15 00:15'
'01/04/15 00:30'
...
Required Output
'01/04/2015 00:00' '01/04/2015 00:15' '01/04/2015 00:30' ...
or
'01-Apr-2015 00:00'
'01-Apr-2015 00:15'
'01-Apr-2015 00:30'
...
I am using R2013a (I saw something about a function datenum but that only came out in 2014)
Thanks Carl
0 个评论
采纳的回答
dpb
2015-1-19
编辑:dpb
2015-1-19
No problem with the date format; tell datenum what format is...
>> dates={'01/04/15 00:15' '01/04/15 00:30'}.'
dates =
'01/04/15 00:15'
'01/04/15 00:30'
>> dstr=datestr(datenum(dates,'dd/mm/yy HH:MM'),'dd-mmm-yyyy HH:MM')
dstr =
01-Apr-2015 00:15
01-Apr-2015 00:30
>>
The above is the "old" datenum/datestr prior to the new class...R2012b, to be precise.
0 个评论
更多回答(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!