inputting dates in format dd/mm/yyyy (or editing a cell array or similar strings without loop)

3 visualizaciones (últimos 30 días)
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

Respuesta aceptada

dpb
dpb el 19 de En. de 2015
Editada: dpb el 19 de En. de 2015
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.

Más respuestas (0)

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by