I have a project, in which I have to use a Matlab Function Block within Simulink. I really would like to use the anonymous function fminbnd to find a minimum of a function within a given interval.
In Matlab this is quite easy. In my specific case the variables xego, yego, m, n, xlow and xup are variable, which are defined in the Matlab Function Block in Simulink.
fun = @(x) sqrt((x-xego)^2+(m*x+n-yego)^2);
[xloc, dis] = fminbnd(fun,xlow,xup);
Now it seems that R2021a does not support fminbnd in a Simulink Function Block, but I need a possibility to find the minimum of a function with function parameters which are defined within the matlab function block.
I do have read about the possibility to call fminbnd as extrinsic function and i tried this with the following code:
function [xloc,dis] = funcmin(fun,xlow,xup)
[xloc, dis] = fminbnd(fun, xlow, xup);
In the Matlab Function Block
[xloc, dis] = funcmin (fun, xlow, xup);
But if i try to run the Simulink model i get the following error text
Function handles cannot be passed to extrinsic functions.
Function 'Lokalisierung' (#24.3039.3042), line 92, column 28:
Launch diagnostic report.
Component: MATLAB Function | Category: Coder error
What is my mistake in this case? Is my idea of handling the parameters to the extrinsic function wrong?
I am really looking forward to your helpful comments!