Changing function handle within a MATLAB Function block in Simulink (Coder error)
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
James Floyd
el 7 de Nov. de 2023
Respondida: Sakshi Sharma
el 8 de Nov. de 2023
I have a function block in Simulink that takes in an input and time and then, based on the input, chooses from a switch-case stack which function to use. The functions being chosen from are named exactly the same but held in 2 different package folders under one larger package folder. The chosen function is then evaluated and the output is returned.
The code inside the MATLAB Function Block looks like this:
function y = calc(t, option)
y = 0;
funcs = cell(2, 1);
funcs{1} = @FunctionPaths.FunctionPath1.dummy; % "dummy" is the name of the function within the FunctionPath1 package
funcs{2} = @FunctionPaths.FunctionPath2.dummy;
switch option
case 1
func = funcs{1};
case 2
func = funcs{2};
otherwise
error('Choice of "option" outside of acceptable range.')
end
y(:) = func(t);
end
The issue comes from the "funcs{2}" line: Type mismatch: MATLAB Coder cannot determine the equivalence of function handles FunctionPaths.FunctionPath1.dummy versus FunctionPaths.FunctionPath2.dummy.
How can I fix this issue?
0 comentarios
Respuesta aceptada
Sakshi Sharma
el 8 de Nov. de 2023
Variable which holds the function handle has to be compile time constant. In this case the function handle variable is 'func'. For this to be constant the function argument 'option' has to be passed as coder.Constant.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre MATLAB Coder en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!