M script: How to find which block is connected to which block?

10 ビュー (過去 30 日間)
Archana
Archana 2015 年 5 月 13 日
コメント済み: Nossier Fawzy 2021 年 5 月 26 日
Hello,
I need to check if a NOT block is connected to/is present just before an "if" condition block. I am unable to write a m script for this scenario. I tried using port handles, port connectivity but somehow I am unable to do it. Any suggestions would be really helpful and much appreciated. Thank you!

採用された回答

Nobel Mondal
Nobel Mondal 2015 年 5 月 13 日
>> load_system(myModel);
>> allBlks = find_system(myModel, 'Type', 'block')
Now this will give you all the blocks in the model. So, you can iterate through and find your If block in the cell-array. Lets, say it is the k-th index.
>> allPorts = get_param(allBlks{k}, 'PortConnectivity')
This will have handles for the all the ports. Now, the 1st port is the inport in the If block. You can check the name/block type which is connected to this port.
>> srcBlkType = get_param(allPorts(1).SrcBlock, 'BlockType')
>> srcBlkName = get_param(allPorts(1).SrcBlock, 'Name')
  2 件のコメント
Archana
Archana 2015 年 5 月 13 日
Thank you very much for the script. I was able to write a similar script but this is simpler and easier to understand :)
Nossier Fawzy
Nossier Fawzy 2021 年 5 月 26 日
Thank you very much

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by