char to double data type
古いコメントを表示
How do I convert the following
164x11 char=
'03-Jan-2018'
'07-Jan-2018'
'07-Jan-2018'..
to 164x11 double=
'03-Jan-2018'
'07-Jan-2018'
'07-Jan-2018'
I want the elements to remain the same and just change the data type
2 件のコメント
Ameer Hamza
2020 年 10 月 24 日
No, it is not possible. And why do you want to do that?
Waqas Siddique
2020 年 10 月 24 日
回答 (2 件)
dpb
2020 年 10 月 24 日
Deprecated (and not recommended) would be
dn=datenum(yourdatechararray,'dd-mmm-yyyy');
which, of course, returns the datenum associated with the date; to get the representation use datestr. But, dn is a double.
The present (and recommended) way to handle dates is to use datetime instead --
dt=datetime(yourdatechararray,'InputFormat','dd-MMM-yyyy');
NB: the input format string representations are NOT the same between the two.
dt is its own class of datetime array, not a double. But, one can do comparisons of equality, greater/less than, etc., as well as plot and such have been extended to recognize the class as inputs.
4 件のコメント
Waqas Siddique
2020 年 10 月 24 日
Waqas Siddique
2020 年 10 月 24 日
Walter Roberson
2020 年 10 月 24 日
fprintf() or compose() -- you will probably find compose() easier.
Steven Lord
2020 年 10 月 24 日
0 投票
I recommend turning the character data representing dates into a datetime array and using that datetime array along with your double data to create a timetable.
カテゴリ
ヘルプ センター および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!