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

조회 수: 35 (최근 30일)
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 CenterFile Exchange에서 Schedule Model Components에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by