Matlab Coder error : converting datetime Format error

I have a problem about Matlab Coder... Actually, The code is correctly run in Matlab, but I want to use Matlab coder. Coder makes error, when I want to change datetime Format. For example, variable DateTime is type of datetime, 2017-05-01 00:00, 2017-05-01 00:15, ...... 2017-09-30 23:45 and I want to change it only year and date like, 20170501, 20170501, ...... , 20170930. That's why I make the code in matlab, d1 = datetime(DateTime, 'Format', 'uuuuMMdd');
DateTime = table2array(datatable(1:row/4,1)); % 2017-05-01 00:00, 2017-05-01 00:15, ...... 2017-09-30 23:45 d1 = datetime(DateTime, 'Format', 'uuuuMMdd'); % 20170501, 20170501, ...... , 20170930
In Matlab, it works correctly. But Matlab Coder can't call the function. I want to know how I can solve this problem...TT

 採用された回答

VBBV
VBBV 2022 年 12 月 12 日

0 投票

Use the dateType argument for the datetime function
d1 = datetime(DateTime, 'dateType', 'yyyymmdd'); % use the dateType argument
instead of
d1 = datetime(DateTime, 'Format', 'uuuuMMdd'); % 20170501, 20170501, ...... , 20170930

4 件のコメント

YunJung Choi
YunJung Choi 2022 年 12 月 13 日
編集済み: YunJung Choi 2022 年 12 月 13 日
TT it doesn't not work in matlab...TT Coder also...TT The error report said that 'Undefinded function or variable 'processedVarArgin'. The first assignment to a local variable determines its class.'
VBBV
VBBV 2022 年 12 月 13 日
編集済み: VBBV 2022 年 12 月 13 日
it seems you are converting table data to array. Convert the table data to cell array as shown below and then use the Format argument
DateTime = table2cell(datatable(1:row/4,1))); % convert the table data to cell array
d1 = datetime(DateTime, 'Format', 'yyyyMMdd'); % use the Format argument
Use MM to represent month instead of mm which represents minutes
YunJung Choi
YunJung Choi 2022 年 12 月 13 日
In the table, there is datetime type. That's why I use table2array... Because value of type 'datetime' in the table, it can't be convertible to 'cell'.
I have a problem only in Matlab Coder... I want to convert from matlab code to c code. Actually my original code has no problem in matlab, but it happens only when I use Matlab Coder codegen...TT Is the correct solution for Matlab Coder?? TT
VBBV
VBBV 2022 年 12 月 14 日
編集済み: VBBV 2022 年 12 月 14 日
Ok, for some reason, Matlab coder doesnt support datetime functions
D = datetime({'2017-05-01 00:00', '2017-05-01 00:15'})
D = 1×2 datetime array
01-May-2017 00:00:00 01-May-2017 00:15:00
T = table(D,'VariableNames',{'D'})
T = table
D __________________________________________ 01-May-2017 00:00:00 01-May-2017 00:15:00
DateTime = table2array(T);
d1 = datetime(DateTime, 'Format', 'uuuuMMdd')
d1 = 1×2 datetime array
20170501 20170501

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

その他の回答 (1 件)

Chetan Bhavsar
Chetan Bhavsar 2022 年 12 月 12 日
編集済み: Chetan Bhavsar 2022 年 12 月 12 日

0 投票

Can you try this once
d1 = datestr(datetime, 'yyyymmdd')
d1 = '20221212'

1 件のコメント

YunJung Choi
YunJung Choi 2022 年 12 月 13 日
it still doesn't work... alarm that codegen is not supported datestr method.

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

カテゴリ

製品

リリース

R2022b

質問済み:

2022 年 12 月 12 日

編集済み:

2022 年 12 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by