フィルターのクリア

Unable to convert the text to datetime using the format: 'dd-MM-yyyy hh:mm'

101 ビュー (過去 30 日間)
Veerle Kohlen
Veerle Kohlen 2020 年 11 月 25 日
コメント済み: Veerle Kohlen 2020 年 11 月 25 日
Hello,
I am trying to convert a my data set in the format seen below into a datetime:
t = datetime(x([9:2445], 1), 'InputFormat', 'dd-MM-yy hh:mm', 'Format', 'hh:mm');
If the data was collected AM, i.e. 22-9-2020 10:35, then the data is converted using date time.
However, if the data was collected PM, i.e. 22-9-2020 15:48, then Matlab gives the error:
Unable to convert the text to datetime using the format: 'dd-MM-yyyy hh:mm'
This is how I load the data:
[x y z] = xlsread(['C:\Users\veerl\Documents\RM HMS\Year 2\Data\Data Collection\nw1\nw1_cosinuss.xlsx']); x = y;
t = datetime(x([9:2445], 1), 'InputFormat', 'dd-MM-yy hh:mm', 'Format', 'hh:mm');
cosinuss.nw1 = struct('Time', t, 'Temperature', str2double(y([9:2445], 3)));
Can someone see where my mistake in understanding the format of the date is? If so please could you provide a solution that will help me read this format of string into a datetime?
Cheers!

採用された回答

Stephan
Stephan 2020 年 11 月 25 日
datetime('22-9-2020 10:35','InputFormat','dd-MM-yy HH:mm')
datetime('22-9-2020 15:48','InputFormat','dd-MM-yy HH:mm')
ans =
datetime
22-Sep-2020 10:35:00
ans =
datetime
22-Sep-2020 15:48:00
  3 件のコメント
Stephan
Stephan 2020 年 11 月 25 日
Note that i used
HH:mm
instead of
hh:mm
Veerle Kohlen
Veerle Kohlen 2020 年 11 月 25 日
Thanks for your help!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by