Borrar filtros
Borrar filtros

How to convert to datenumber from two cell values

3 visualizaciones (últimos 30 días)
Duncan Wright
Duncan Wright el 15 de Feb. de 2018
Comentada: Duncan Wright el 15 de Feb. de 2018
date = cell2mat(tmp{1}(1))
time = cell2mat(tmp{1}(2))
dt = datenum([date time], 'dd:mm:yyyy HH:MM:SS')
Error using datenum (line 181)
DATENUM failed.
Caused by:
Error using dtstr2dtnummx
Failed to convert from text to date number.
What exactly am i doing wrong here?
Thanks in advance
  5 comentarios
Jos (10584)
Jos (10584) el 15 de Feb. de 2018
As Jan already hinted at, add a space between date and time
str = [date ' ' time]
datum(str, 'dd:mm:yyyy HH:MM:SS')
Jan
Jan el 15 de Feb. de 2018
Editada: Jan el 15 de Feb. de 2018
What exactly is a "cell structure"? The explanation is not clear:
tmp{1}(1) = 26:05:2017
This is no valid Matlab syntax, therefore the readers have to guess, what it exactly means. Maybe it is a string object:
tmp{1}(1) = "26:05:2017"
Or a cell string:
tmp{1}(1) = {'26:05:2017'}
Please do not let us guess the details. I could post some code and test it, if you show us some valid Matlab code to create the inputs.
Are you sure that the date is written with colons? This is rather unusual.

Iniciar sesión para comentar.

Respuesta aceptada

Peter Perkins
Peter Perkins el 15 de Feb. de 2018
In any case, if you are using a recent Version of MATLAB (R2014b or later), consider moving to datetimes, not datenums:
>> date = '26:05:2017';
>> time = '16:05:30';
>> dt = datetime([date ' ' time],'Format','dd:MM:yyyy HH:mm:ss')
dt =
datetime
26:05:2017 16:05:30
>> dt = datetime([date ' ' time],'InputFormat','dd:MM:yyyy HH:mm:ss')
dt =
datetime
26-May-2017 16:05:30

Más respuestas (0)

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by