フィルターのクリア

Code for connecting two Simscape blocks

11 ビュー (過去 30 日間)
Alicia Roder
Alicia Roder 2017 年 3 月 24 日
編集済み: Steve Miller 2018 年 2 月 1 日
I am trying to connect two Simscape blocks. My first step is to get the corresponding handles for both blocks with e.g.
>> A=get_param('Pressure/FixedOrifice','LineHandles')
and analog for the second block.
Then I try to connect the blocks via
>> add_line(A.RConn(1,2),B.LConn(1,2))
since the blocks have more than one RConn/LConn. This gives me an error. How do I adress the ports correctly?
Thank you for your help.
  1 件のコメント
Steve Miller
Steve Miller 2017 年 3 月 25 日
編集済み: Steve Miller 2018 年 2 月 1 日
We have posted an example on the MATLAB Central File Exchange that shows how to use MATLAB commands to add Simscape blocks and connect them.
I bet you can reuse some of the code in this example in your work.
Thanks,
--Steve

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

回答 (1 件)

Aniruddha Katre
Aniruddha Katre 2017 年 3 月 24 日
This did not work because Line Handles gives you handles to lines that exist. If you look at the struct A, it has the values "-1" for LConn and RConn indicating that there is no line connecting those ports.
Instead you need to use the parameter "PortHandles" when using get_param.
B1 = get_param(gcb,'PortHandles') % Port handles for first block
B2 = get_param(gcb,'PortHandles') % Port handles for second block
add_line(gcs,B1.RConn,B2.LConn)
For more details see the last section of the description part of the add_line documentation page: http://www.mathworks.com/help/simulink/slref/add_line.html
Hope this helps!
  1 件のコメント
Alicia Roder
Alicia Roder 2017 年 3 月 27 日
Thank you. I have tried that out, but it still gives me the error "invalid Simulink object name". I disconnected the the corresponding elements from the network completely in order to eliminate additional errors although I need it to function with some connections already existing. Deleting the connecting lines via MATLAB was no problem.

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

カテゴリ

Help Center および File ExchangeSimulation and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by