How can I convert a cell array of "random dates in the year" into time in year?
Ältere Kommentare anzeigen
For ex: My input vector has random dates like 1993-4-1,1993-4-28 etc.Output should be 1993.000,1993.0039,1993.0078.I have used different functions (datevector, datenum etc). But they convert the date either to date numbers (730990) or yr month day format; not in the above output form. Btw I have to extract the input array from a .mat file. Thanks...
Akzeptierte Antwort
Weitere Antworten (1)
Here's a way using datetime,
>> yourDates=datetime({ '1993-4-1','1993-4-28'},'InputFormat','yyyy-M-d')
yourDates =
01-Apr-1993 28-Apr-1993
>> doy=day(yourDates,'dayofyear');
>> [Y,M,D]=ymd(yourDates); M(:)=12; D(:)=31;
>> doyDec31=day(datetime(Y,M,D),'dayofyear');
>> result=Y+doy/doyDec31;
Kategorien
Mehr zu Dates and Time finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!