Filter löschen
Filter löschen

How to convert to datenumber from two cell values

3 Ansichten (letzte 30 Tage)
Duncan Wright
Duncan Wright am 15 Feb. 2018
Kommentiert: Duncan Wright am 15 Feb. 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 Kommentare
Jos (10584)
Jos (10584) am 15 Feb. 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 am 15 Feb. 2018
Bearbeitet: Jan am 15 Feb. 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Peter Perkins
Peter Perkins am 15 Feb. 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

Weitere Antworten (0)

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by