Function 'daysact' not supported for code generation.

2 次查看(过去 30 天)
I am using this simple code inside a user defined Matlab function in SIMULINK
NumDays = daysact('20-March','21-March');
But it shows error that "Function 'daysact' not supported for code generation."

采纳的回答

Walter Roberson
Walter Roberson 2021-1-14
Correct. That function cannot be compiled.
The work-around is to use datetime and subtract.
dt1 = datetime('7-sep-2002','Locale','en_US')
dt1 = datetime
07-Sep-2002
dt2 = datetime('25-dec-2002','Locale','en_US')
dt2 = datetime
25-Dec-2002
NumDays = daysact(dt1, dt2) %what you cannot generate code for
NumDays = 109
NumDays2 = days(dt2-dt1) %replacement function
NumDays2 = 109

更多回答(1 个)

Sean de Wolski
Sean de Wolski 2021-1-14
You should use the newer and recommended datetime / duration classes which support c-codegen:
d = days(datetime(t1)-datetime(t2));

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by