How do I get the x,y coordinates of port handles on a susbsytem block?

37 ビュー (過去 30 日間)
Jeff Fetta
Jeff Fetta 2017 年 3 月 24 日
コメント済み: ciming zhu 2023 年 4 月 27 日
How can I determine, programmatically (that is, in an M-script), the position of these port handles on a subsystem? As the subsystem resizes, or as ports are added, the "bubbled up" representation on the subsystem block changes; I want to position other elements relative to these ports and thus need to be able to determine their final positions.

採用された回答

Jeff Fetta
Jeff Fetta 2017 年 3 月 24 日
Well, I answered my own question...PortConnectivity is the parameter I was looking for. Here is some code that will "clean up" the input and output ports for a subsystem like that above (assuming input and output port blocks are connected to the subsystem block). Make sure you select the subsystem to clean-up first!
% get the subsystem port handle positions
pc = get_param(gcb,'PortConnectivity');
% distance from the subsystem to the port
offset = 200;
for i = 1:numel(pc)
% position of port connector
y = pc(i).Position(2);
x = pc(i).Position(1);
% port block handle and size
if isempty(pc(i).SrcBlock)
ph = pc(i).DstBlock;
off = -(offset-50); % asthetics here...related to the width of the port block
else
ph = pc(i).SrcBlock;
off = offset;
end
% port block dimmensions
pp = get_param(ph,'Position');
w = pp(3)-pp(1);
h = pp(4)-pp(2);
% adjust position of port block
set_param(ph,'Position',[x-off,y-h/2,x-off+w,y+h-h/2]);
end

その他の回答 (1 件)

Praveen Kumar
Praveen Kumar 2019 年 6 月 24 日
Hi,
I need help, how to backtrace the inport in between the two subsytems.
Subsystem - A is connected with Subsystem - B. I want Subsystem - B 1st inport is connected to which outport of Subsystem - A.
I need programmatically.
Anyone help me.
  1 件のコメント
ciming zhu
ciming zhu 2023 年 4 月 27 日
Have you sloved this problem,if you did,plz tell me how did you make it,thanks a lot.

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

カテゴリ

Help Center および File ExchangeSchedule Model Components についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by