How can I get the port number of a StateFlow input given it's handle programatically?

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?

1 件のコメント

David Berggren
David Berggren 2025 年 2 月 6 日
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

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

 採用された回答

Jorge Calvo
Jorge Calvo 2021 年 10 月 5 日

1 投票

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 件のコメント

Jorge Calvo
Jorge Calvo 2021 年 10 月 5 日
PS. If you are running an older version, you might have to use comma-separated values for find:
x = find(sfgco,"Id","301");
Eric Bender
Eric Bender 2021 年 10 月 8 日
Hi Jorge, thank you for that suggestion however I am running a script programmatically which just gives me the handles (ID) to the StateFlow input data items. There is nothing actually being selected by the script so when I do a sfgco I get the empty list []. I thought having the StateFlow input data item ID would be sufficient as I'm working "upwards" from only having the SF ID to seeing the connected Simulink input line name. Do you have any other suggestions?
Jorge Calvo
Jorge Calvo 2021 年 10 月 8 日
編集済み: Jorge Calvo 2021 年 10 月 8 日
You can use sfroot instead of sfgco. That will look at all the Stateflow charts you have loaded.
>> x = find(sfroot,Id=301);
Eric Bender
Eric Bender 2021 年 10 月 8 日
Fantastic!!! Thank you Jorge that worked perfectly.

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

その他の回答 (0 件)

カテゴリ

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

製品

リリース

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by