Is there a way to get MATLAB Function name defined in Simulink block programmatically ?

  • I would like to know whether the MATLAB Function block created in Simulink can be programatically check or parameters of the function can be obtained.
  • For example
y = fcn(u) or y = FunctionName(u)
I would like to get the function name fcn or FunctionName

2 件のコメント

Steven Lord
Steven Lord 2023 年 2 月 1 日
How are you hoping to use this information if it's available? What are you planning to use it for?
Shiva Haresh
Shiva Haresh 2023 年 2 月 1 日
It's for a custom Simulink Check

サインインしてコメントする。

 採用された回答

Finding the function line is easy because it's the first line that starts with "function". Just need to deal with the different possibilities for the function signature.
For example, to find the function line
config = get_param(gcb,'MatlabFunctionConfiguration');
fline = strip(split(string(config.FunctionScript),newline));
fline = fline(startsWith(fline,"function"))
fline = fline(1);
fline =
"function img = fcn(lambd,m,n)"
% assign to fline here to see rest of processing to find the function name
fline = "function img = fcn(lambd,m,n)";
% this logic for typical signature: function (outputlist) = fcn (inputlist)
if contains(fline,"=")
fline = extractAfter(fline,"=")
if contains(fline,"(")
function_name = strip(extractBefore(fline,"("))
end
end
fline = " fcn(lambd,m,n)"
function_name = "fcn"
Would need to implement logic for all possible function signatures.

その他の回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2023 年 2 月 1 日

1 投票

myconfig = get_param(gcb, 'MATLABFunctionConfiguration') and parse the text, you might be able to get it.
web(fullfile(docroot, 'simulink/slref/simulink.matlabfunction.matlabfunctionconfiguration.html'))

4 件のコメント

Shiva Haresh
Shiva Haresh 2023 年 2 月 1 日
I tried this already but I couldn't get the function name as output.
for example,
  • system = load_system('sacv.slx');
  • x = get_param(gcb, 'MATLABFunctionConfiguration');
Did I miss another step here?
Fangjun Jiang
Fangjun Jiang 2023 年 2 月 1 日
編集済み: Fangjun Jiang 2023 年 2 月 1 日
You need to parse x.FunctionScript
The function name shows up on the icon and it changes as the user changes the function name. So I think it's already been parsed but I couldn't find it through block properties or 'MATLABFunctionConfiguration'
Shiva Haresh
Shiva Haresh 2023 年 2 月 1 日
But this FunctionScript has the entire input and output along with the function name.
Shiva Haresh
Shiva Haresh 2023 年 2 月 2 日
Thank you so much @Fangjun Jiang

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeSimulink についてさらに検索

製品

リリース

R2022b

質問済み:

2023 年 2 月 1 日

コメント済み:

2023 年 2 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by