How to convert a column date wich contains NaN?

13 ビュー (過去 30 日間)
Viridiana  Torres
Viridiana Torres 2016 年 4 月 30 日
コメント済み: Viridiana Torres 2016 年 5 月 1 日
HI!!
I hope you can help me to solve this doubt:
I have a column with number and NaN at the same time, lets say for example:
T= [199001021003.00;
199001021008.00;
NaN;
NaN]
The numbers are dates in the format yyyymmddHHMM and I want to convert those numbers into dates in Matlab format.
When I applied the next code:
D= datenum(num2str(T),'yyyymmddHHMM');
C= datestr(D,0);
It can´t recognize the NaN and therefore I have the next error:
"Error using datenum (line 179) DATENUM failed.
Caused by: Error using dtstr2dtnummx Failed on converting date string to date number"
How can I fix this and make Matlab doesn´t recogized the NaN and keeps giving the dates in Matlab format?
Thanks in advance!

採用された回答

CS Researcher
CS Researcher 2016 年 4 月 30 日
You should remove the NaN entries first. DO this:
T(isnan(T)) = [];
D= datenum(num2str(T),'yyyymmddHHMM');
C= datestr(D,0);
  1 件のコメント
Viridiana  Torres
Viridiana Torres 2016 年 5 月 1 日
Perfect!!! Thanks :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by