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
1 个评论
Minutes should be 'MM' not 'MN'
采纳的回答
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.
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 的更多信息
产品
另请参阅
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
