How to call extrisic m-file contains function handle in SIMULINK user-defined MATLAB function?
조회 수: 2 (최근 30일)
이전 댓글 표시
I am trying to understand how to call extrisic m-file contains function handle in SIMULINK user-defined MATLAB function. Here I wrote a test to call an extrisic m-file named "fun_kk" in my SIMULINK user-defined MATLAB function as below:
***********************
function y = actuator(u)
coder.extrinsic('fun_kk')
d = fun_kk(u);
y = d;
**************************
And the "fun_kk" is:
*****************
function d = fun_kk(u)
d = sqrt(@(u)u^2);
*****************
After runnung SIMULINK by giving a contant input u, the error message apears:
Function output 'y' cannot be an mxArray in this context.
Consider preinitializing the output variable with a known type.
Function 'MATLAB Function' (#159.9.10), line 1, column 10:
"y"
Launch diagnostic report.
Could anyone please help me to solve this problem?
댓글 수: 0
답변 (3개)
Ryan Livingston
2017년 2월 14일
편집: Ryan Livingston
2017년 2월 14일
You can see the explanation of this here:
Namely, the code generator can't know the output type of the extrinsic function call. You can pre-assign the output to tell it what the type, size, and complexity are:
coder.extrinsic('fun_kk')
y = 1; % assuming real scalar double output for fun_kk
% change to match the expected type, size, complexity
y = fun_kk(u);
Now, fun_kk only uses constructs which are supported for codegen (anonymous functions are supported as of R2016b) so there's no need to use coder.extrinsic. Just call fun_kk, omit the coder.extrinsic, and everything should work out.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Simulink Functions에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!