How to set the location of the port with code?

In the description of Matlab help: Flexible port placement in Simulink Editor lets you move ports by clicking and dragging the port along the block icon outline, and this way you can put ports on any side of a Subsystem block, including top and bottom. The Port location on the parent subsystem parameter does not have separate values for top or bottom. If you drag a port to a different location on the Subsystem block icon, the parameter value automatically changes to reflect the new placement: Left — The port appears on the left or top side of the subsystem icon. Right — The port appears on the right or bottom side of the subsystem icon.
How to use code to realize the function of changing port location? For example, add a port dynamically and place it on the top of the icon.

Answers (1)

See the article "Programmatic Model Editing" in the Simulink documentation.

5 Comments

I can't find a way to change the position of the port on the icon side by code in the simulink documentation.Just manually drag and drop to move the port location is ok.
Programmatically I think you do that by rotating the block. Here are some sample commands, assuming you have opened a model and selected the block you want to change programmatically. The selected block will be called gcb in MATLAB.
>> set_param(gcb, 'Orientation', 'down')
>> get_param(gcb, 'Position')
ans =
95 170 125 200
>> set_param(gcb, 'Position', [95 170 105 200])
>>
I have found the instruction to position the port to the left or right.
set_param(gcb,'Side','Left').
But the port cannot be placed on the top or bottom of the icon Programmatically .
You may need to use a combination of the 'Orientation' and 'Side' parameters to achieve the results you want. These properties sound similar to the block rotate and block flip options that you see when you right click on a block and get a pop up menu.
How can I place the ports at bottom or top of the subsystem programatically, becasue side parameter has only two inputs left and right.

Sign in to comment.

Categories

Asked:

on 31 Jan 2022

Edited:

on 21 Dec 2023

Community Treasure Hunt

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

Start Hunting!