Function 'datenum' not supported for code generation. Function 'MATLAB Function'
조회 수: 8 (최근 30일)
이전 댓글 표시
The following picture is a part of the Simulink model and I use the MATLAB Fcn (Library function) to call the datenum function.
functiontime = funcPlotGraph(xAxis, yAxis, timeperiod1, timeperiod2)
legendsCol = {};
dim = 2;
% Convert long tick time to DateTime
time = datetime(datestr(xAxis/86400000 + datenum(1970,1,1)));
% plot graph between time vs yAxis
plot(xAxis, yAxis);
legendsCol{end+1} = 'Actual';
hold on
if ~isequal(timeperiod1, '0')
% average
movingAve = movmean(yAxis, timeperiod1);
plot(time, movingAve);
legendsCol{end+1} = 'Avg';
end
if ~isequal(timeperiod2, '0')
% average
movingAve20 = movmean(yAxis,timeperiod2);
plot(time, movingAve20);
legendsCol{end+1} = 'Avg 2';
I'm getting the following error while compiling the model:
Function 'datenum' not supported for code generation. Function 'MATLAB Function' (#88.184.201), line 5, column 43: "datenum(1970,1,1)" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Simulink does not have enough information to determine output sizes for this block. If you think the errors below are inaccurate, try specifying types for the block inputs and/or sizes for the block outputs.
Component:MATLAB Function | Category:Coder error
Undefined function or variable 'time'. The first assignment to a local variable determines its class. Function 'MATLAB Function' (#88.409.413), line 15, column 14: "time" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable 'time'. The first assignment to a local variable determines its class. Function 'MATLAB Function' (#88.558.562), line 22, column 8: "time" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Errors occurred during parsing of MATLAB function 'TestMatlabModelOld/MATLAB Function'
Component:MATLAB Function | Category:Coder error
Simulink cannot determine sizes and/or types of the outputs for block 'TestMatlabModelOld/MATLAB Function' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Component:MATLAB Function | Category:Coder error
Simulink cannot determine sizes and/or types of the outputs for block 'TestMatlabModelOld/MATLAB Function' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Component:Simulink | Category:Model error
댓글 수: 0
답변 (2개)
Siddharth Bhutiya
2020년 10월 22일
편집: Siddharth Bhutiya
2020년 10월 22일
As the error indicates, datenum is not supported for code generation. However, datetime does support code generation and it is recommended to use datetime over datenum, even when not doing code generation.
Is there a specific reason you are trying to use datenum over datetime ?
댓글 수: 2
Piotr Kolodziej
2021년 12월 10일
How can I convert datetime result to "Serial date number" with code generation?
Steven Lord
2021년 12월 10일
Let's get a sample date number.
n = datetime('now') % Use for comparison later
d = datenum(n)
Now to convert d back into a datetime like n, call datetime with the 'ConvertFrom' name-value pair argument.
n2 = datetime(d, 'ConvertFrom', 'datenum')
I believe this syntax is supported for code generation.
Eduardo Gil
2022년 6월 16일
Well, I tried datetime(d,'ConvertFrom','datenum') for an Excel addin - it didnt work (the compiled code returns me an error, even though in Matlab the function works fine). Problem is in Excel a date is a number - and there is a different date convention in Excel vis a vis Matlab. So this function would be a good way to make the conversion. Any thoughts here? I had to google to the end of the Internet to find this post - which seems very much related to the error I am getting.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!