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.
댓글 수: 0
채택된 답변
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 Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!