Anonymous Function doesn't work with Simulink

6 views (last 30 days)
Onur Ersoy
Onur Ersoy on 19 Dec 2019
Commented: Walter Roberson on 29 Dec 2019
I am trying to build my model in external mode. In this model i have a function block that contains the following code;
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
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 Comment
Walter Roberson
Walter Roberson on 29 Dec 2019
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.

Sign in to comment.

Answers (1)

Mark McBroom
Mark McBroom on 29 Dec 2019
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.




Community Treasure Hunt

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

Start Hunting!