필터 지우기
필터 지우기

Changing function handle within a MATLAB Function block in Simulink (Coder error)

조회 수: 6 (최근 30일)
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?

채택된 답변

Sakshi Sharma
Sakshi Sharma 2023년 11월 8일
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개)

카테고리

Help CenterFile Exchange에서 String에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by