Anonymous Function doesn't work with Simulink
조회 수: 1 (최근 30일)
이전 댓글 표시
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
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
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')
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Configure and View Diagnostics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!