How to auto-adjust the subsystem height to make the spacing between adjacent ports consistent?

조회 수: 8 (최근 30일)
When I increase or decrease the number of ports of a subsystem, the spacing between two adjacent ports will be change if I don't adjust the height of Subsystem.
I hope that the subsystem ports spacing can be consistent throughout my entire model,So I use something be like the code below to adjust the height of selected subsystem:
portsNum = max(inputPorts_Num, outputPorts_Num);
Sub_Pos = get_param(gcbh,'Position'); %select target subsystem
NewHeight = old_pos(4)-old_pos(2)+temp*portsNum; %Calculate the new height of subsystem according to the number of ports
Sub_Pos = [Sub_Pos(1) Sub_Pos(2) Sub_Pos(3) Sub_Pos(2)+NewHeight];
set_param(gcbh,'Position',Sub_Pos);
But, I found that how much height of subsystem should I change to keep the spacing between adjacent ports consistent, is not as simple as I thought.
I try to increase more ports,adjust the height manually to make the spacing consistent,and then get the Position value to cal the increased height,try to find out the rule between ports-increasing and height-adjusting.
and there seems to be no rules...
I know a stupid way to achieve my purpose: Increase more and more ports and cal every height vale to make an Height-array. Then look up table.
But that's really stupid...
Can anybody help me to do this by a smarter way? Thank you very much.

채택된 답변

Fangjun Jiang
Fangjun Jiang 2024년 3월 6일
I had this problem before. I didn't find an exact formula. I suggest not looking at the previous height. Just use this formula to set the height. Height=Spacing*(portsNum+1). For a range of Spacing and portsNum, it works pretty well.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by