Is there a way to get MATLAB Function name defined in Simulink block programmatically ?
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
- 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 commentaires
Steven Lord
le 1 Fév 2023
How are you hoping to use this information if it's available? What are you planning to use it for?
Réponse acceptée
Paul
le 2 Fév 2023
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
Would need to implement logic for all possible function signatures.
Plus de réponses (1)
Fangjun Jiang
le 1 Fév 2023
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 commentaires
Voir également
Catégories
En savoir plus sur Simulink Functions dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!