How can I get the port number of a StateFlow input given it's handle programatically?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Eric Bender
le 22 Juil 2021
Commenté : David Berggren
le 6 Fév 2025 à 10:48
I have the handle of a StateFlow input from a previous find result. I'm trying to get the port number for that StateFlow input. I've been using the sf('get',<handle num>,<field name>) command for other fields like 'data.name', 'data.scope', etc. but can't see where I can get the port number. Can anyone help me with this?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/692414/image.jpeg)
1 commentaire
David Berggren
le 6 Fév 2025 à 10:48
chart = find(sfroot, '-isa', 'Stateflow.Chart', 'Name', 'YourChartName');
inputs = chart.find('-isa', 'Stateflow.Data', '-and', 'Scope', 'Input');
for i = 1:numel(inputs)
fprintf('Port %d: %s\n', inputs(i).Port, inputs(i).Name);
end
Réponse acceptée
Jorge Calvo
le 5 Oct 2021
It sounds like you are working with Stateflow.Data objects, where you have the ID property and want to find the Port property. In that case, you can do this:
>> x = find(sfgco,Id=301);
>> x.Port
4
4 commentaires
Jorge Calvo
le 8 Oct 2021
Modifié(e) : Jorge Calvo
le 8 Oct 2021
You can use sfroot instead of sfgco. That will look at all the Stateflow charts you have loaded.
>> x = find(sfroot,Id=301);
For more information, you can check out: https://www.mathworks.com/help/stateflow/api/overview-of-the-stateflow-api.html.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Complex Logic 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!