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 comentarios

Ameer Hamza
Ameer Hamza el 24 de Oct. de 2020
No, it is not possible. And why do you want to do that?
Waqas Siddique
Waqas Siddique el 24 de Oct. de 2020
I have 4 variables
a=164x11 double
b=164x11 double
c=164x11 double
d=164x11 char
I am using the command to display
e=[a,b,c,d]
so I get an error
Error using datetime/horzcat (line 1335)
All inputs must be datetimes or date/time character vectors or date/time strings.

Iniciar sesión para comentar.

Respuestas (2)

dpb
dpb el 24 de Oct. de 2020

0 votos

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 comentarios

Waqas Siddique
Waqas Siddique el 24 de Oct. de 2020
datenum is changing the date to numbers.
I want to display these types together
a=164x11 double=1,2,3...
b=164x11 double=1,2,3...
c=164x11 double=1,2,3...
d=164x11 char=
'03-Jan-2018'
'07-Jan-2018'
'07-Jan-2018'..
I am using the command to display
e=[a,b,c,d]
How can I display the different data types together
Waqas Siddique
Waqas Siddique el 24 de Oct. de 2020
e=
1 1 1 737063
2 2 2 737067
3 3 3 737067
Right now I am getting this
Walter Roberson
Walter Roberson el 24 de Oct. de 2020
fprintf() or compose() -- you will probably find compose() easier.
dpb
dpb el 24 de Oct. de 2020
Editada: dpb el 25 de Oct. de 2020
Or, depending upon what you mean, exactly, by "display", put them in a table and the ML table data display will handle automagically...
ADDENDUM:
Oh, I see Steven L already suggested via timetable..."great minds ..." :)

Iniciar sesión para comentar.

Steven Lord
Steven Lord el 24 de Oct. de 2020

0 votos

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.

Categorías

Etiquetas

Preguntada:

el 24 de Oct. de 2020

Editada:

dpb
el 25 de Oct. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by