How to call extrisic m-file contains function handle in SIMULINK user-defined MATLAB function?

2 ビュー (過去 30 日間)
LEE YUMY
LEE YUMY 2015 年 3 月 2 日
回答済み: Fayez Alruwaili 2021 年 1 月 29 日
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?

回答 (3 件)

Thomas Marullo
Thomas Marullo 2015 年 12 月 4 日
Have you solved this problem? I am having the same problem.

Ryan Livingston
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.

Fayez Alruwaili
Fayez Alruwaili 2021 年 1 月 29 日
d = zeros (r,c)
d = fun_kk(u);
....

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by