Anonymous Function doesn't work with Simulink

1 回表示 (過去 30 日間)
Onur Ersoy
Onur Ersoy 2019 年 12 月 19 日
コメント済み: Walter Roberson 2019 年 12 月 29 日
I am trying to build my model in external mode. In this model i have a function block that contains the following code;
f=@(X1)myFun(X1,x1,y1,z1)
X1 = fsolve(f,[1,1,1]);
and in my function file i am trying to find a vector (x2,y2,z2) that is a unit vector and perpendicular to my existing vector (x1,y1,z1). The code is as follows;
function F = myFun(X1,x1,y1,z1)
% x2=X1(1);y2=X1(2);z2=X1(3);
F(1) = x1*X1(1)+y1*X1(2)+z1*X1(3)
F(2) = X1(1)*X1(1)+X1(2)*X1(2)+X1(3)*X1(3)-1
end
When i try build the model, the following error appears;
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
Anonymous functions are not supported for code generation.
Function 'ForwardKinematics' (#24.1996.1997), line 77, column 3:
"@"
Launch diagnostic report.
I am using Matlab 2015b. Thanks for your help.
  1 件のコメント
Walter Roberson
Walter Roberson 2019 年 12 月 29 日
I seem to recall that the restriction is against having anonymous functions directly in the function that is the MATLAB Function Block, and that if you instead have that block call a function that does the work, then that would be permitted.
I have never attempted this myself, so I am not certain it will work.

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

回答 (1 件)

Mark McBroom
Mark McBroom 2019 年 12 月 29 日
try using making the two functions extrinsic. This tells Simulink to not try and generate code for these 2 functions, but to rather run the 2 functions in interpretted mode. This will slow down the simulation speed but should get around the errors.
coder.extrinsic('myFun')
coder.extrinisic('fsolve')

カテゴリ

Help Center および File ExchangeConfigure and View Diagnostics についてさらに検索

製品


リリース

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by