필터 지우기
필터 지우기

How to convert to datenumber from two cell values

조회 수: 3 (최근 30일)
Duncan Wright
Duncan Wright 2018년 2월 15일
댓글: Duncan Wright 2018년 2월 15일
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
Jos (10584)
Jos (10584) 2018년 2월 15일
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 2018년 2월 15일
편집: Jan 2018년 2월 15일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Peter Perkins
Peter Perkins 2018년 2월 15일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by