Problem with datenum usage

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

 采纳的回答

Iain
Iain 2014-8-8

0 个投票

Its a typo:
'yyyymmddHHMN'
MN should be MM

14 个评论

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.
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.
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
Well, the decimal is new.
The format line has to match the data. See if this works:
Time = datenum(num2str(x),'yyyymmdd.HHMM');
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.
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.
What values do you have in A(:,1) - I want to see the min & max.
George
George 2014-8-11
编辑:George 2014-8-11
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
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)
@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?
It fails when two numbers are given to it. I don't know why.
thank you everybody for your help :) !

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Time Series Objects 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by