Hi
I am trying to use the datenum function of matlab to convert into dates I read through the manual in matlab andhave used
Time = datenum(num2str(time),'yyyymmdd');
which works but when i change it to also register the Hours and Minutes in failed
time = A(:,1);
Time = datenum(num2str(time),'yyyymmddHHMN');
S.Time=Time
DATENUM failed.
Error in SWAN2buoy (line 29)
Time = datenum(num2str(time),'yyyymmddHHMN');
Caused by:
Error using cnv2icudf (line 131)
Unrecognized minute format. Format string: yyyymmddHHMN.`
have to say that I am using datenum to read timeseries from a file i have, and i would like to have it it a full timeseries form The original uploaded date format is
2.010010100300000e+07
thank you

 Respuesta aceptada

Iain
Iain el 8 de Ag. de 2014

0 votos

Its a typo:
'yyyymmddHHMN'
MN should be MM

14 comentarios

George
George el 8 de Ag. de 2014
Have tried that as well, and its the same fail
Time = datenum(num2str(time),'yyyymmddHHM');
Error using datenum (line 179)
DATENUM failed.
Error in SWAN2buoy (line 29)
Time = datenum(num2str(time),'yyyymmddHHM');
Caused by:
Error using cnv2icudf (line 131)
Unrecognized minute format. Format string: yyyymmddHHM.
Star Strider
Star Strider el 8 de Ag. de 2014
You deleted the ‘N’ but didn’t replace it with an ‘M’.
Try this:
Time = datenum(num2str(time),'yyyymmddHHMM');
As Iain pointed out, there's a typo:
>> datenum('201408081539','yyyymmddHHMM')
ans =
7.3582e+005
You have only one M instead of two.
George
George el 8 de Ag. de 2014
The initial format of the date is
x =20100101
20100101.0030000
20100101.0100000
20100101.0130000
20100101.0200000
I have tried the
Time = datenum(num2str(x),'yyyymmddHHMM');
but i get the mentioned error
Star Strider
Star Strider el 8 de Ag. de 2014
Well, the decimal is new.
The format line has to match the data. See if this works:
Time = datenum(num2str(x),'yyyymmdd.HHMM');
George
George el 11 de Ag. de 2014
Hello
I tried with the decimal indicator but it does not work either
Time = datenum(num2str(x),'yyyymmdd.HHMM')
Error using datenum (line 179)
DATENUM failed.
Caused by:
Error using dtstr2dtnummx
Failed on converting date string to date number.
Hikaru
Hikaru el 11 de Ag. de 2014
If x is
x = [20100101;
20100101.0030000;
20100101.0100000;
20100101.0130000;
20100101.0200000]
Can you tell us what the numbers in the decimal places means? The following
Time = datenum(num2str(x(n)),'yyyymmdd.HHMM');
works for n = 1,3, and 5. But it fails for n = 2 and 4, so I guess it has something to do with the format.
Iain
Iain el 11 de Ag. de 2014
What values do you have in A(:,1) - I want to see the min & max.
George
George el 11 de Ag. de 2014
Editada: George el 11 de Ag. de 2014
the values after the decimal represent the hours and minutes of the recording
the min is the starting time 20100101.000000 and the end (max) 20101231.180000
I did not upload the whole column so as to save space
Iain
Iain el 11 de Ag. de 2014
Ok, I figured it out.
datenum only works on ONE number at a time. Loop through, one element at a time, and it should work.
Time = arrayfun(@(d) datenum(sprintf('%1.6f\n',d),'yyyymmdd.HHMMSS'),x)
George
George el 11 de Ag. de 2014
@Michael Haderlein, thank you very much this is working .
may i ask why does datenum fails when a large series of number is given to it?
Iain
Iain el 11 de Ag. de 2014
It fails when two numbers are given to it. I don't know why.
George
George el 11 de Ag. de 2014
thank you everybody for your help :) !

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Preguntada:

el 8 de Ag. de 2014

Comentada:

el 11 de Ag. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by