Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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.

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 6 de Mzo. de 2024
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.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by