Programmically re-order model reference inports in Simulink

15 次查看(过去 30 天)
When you use the model reference block in Simulink you can reorder the inputs (and outputs) of the block dynamically via dragging the input ports in a new order. This action does not change the numbering of the inports inside the referenced model.
Left: The referenced model; Right: The model reference block
Left: The referenced model (still with the same ordering of inputs); Right: The model reference with the ordering changed (via drag-drop)
Now, I want to change the ordering of the model reference block programmically. How can I do this?
I have not found anything in get_param() or get() that could be used to achieve this.
(Although, in PortConnectivity, the Position of the Port is updated when they are moved. However, the PortConnectivity is read-only access only)

回答(1 个)

Fangjun Jiang
Fangjun Jiang 2023-8-17
This is interesting. A user could drag and drop the ports, to a different order or even to the top, bottom or right side of the block. The port "Position" value got changed but you can't set it programmingly because it is read-only.
I don't know what is the practical benefit of moving the ports around, especially in the case that you want to do it programmingly. I knew this feature and it provides some convenience or graphical beauty when connecting blocks manually. But it could also confuse uses regarding the connection. If after all the blocks are connected correctly, a user could move (or by accidental drag and drop) the ports on the left side to a different order. It looks like that the connection has bee changed but it does not.
  1 个评论
Michael Zauner
Michael Zauner 2023-8-18
My use-case is a bit exotic for it. We have a block with ~300 inputs and outputs where the port-ordering can't be changed due to backwards-compatibility. However, we do not require all inputs und outputs for every use-case. So my goal was to move the ports that are used to the top and the ones that aren't to the bottom. This way, we can connect auxilary systems easily with the "Ctrl+click" functionality (automatically creates lines between two blocks) without having to hand-wire everything.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Modeling 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by