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

11 次查看(过去 30 天)
  • 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

采纳的回答

Paul
Paul 2023-2-2
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
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 个评论

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by