フィルターのクリア

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 Center および File ExchangeString についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by