Datenum not failiing as expected
1 回表示 (過去 30 日間)
古いコメントを表示
Hi
I am using datenum to convert strings to serial datenum, using a specified string format. But I have a problem, datenum returns a value even if the string is not on the specified format. e.g
datenum('20140630-12022', 'yyyymmdd-HHMMSS')
returns a valid number even if the time field is a digit short. This even works
datenum('201406-120223', 'yyyymmdd-HHMMSS')
missing two of the digits of the date field. Is it possible to make datenum more strict, or is there other ways to verify the format?
0 件のコメント
回答 (1 件)
dpb
2014 年 6 月 24 日
Build a verification function before passing to datenum -- something on the order of
>> ds={'20140630-12022';'201406-120223';'20140630-120224'};
>> cellfun(@(s) strfind(s,'-')==9 & length(s)==15,ds)
ans =
0
0
1
>>
This one checks for the proper length of date field and overall; hence the time field must be same length as well. Doesn't do anything about verifying reasonable values, of course.
regexp could be of use in verifying patterns, too, depending on how much qualifying you want to do.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Time Series Objects についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!