フィルターのクリア

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
  1 件のコメント
Duncan Wright
Duncan Wright 2018 年 2 月 15 日
Thanks for the tip!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by