How to set the location of the port with code?
Show older comments
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)
Benjamin Thompson
on 31 Jan 2022
0 votes
See the article "Programmatic Model Editing" in the Simulink documentation.
5 Comments
asdfa asdf
on 1 Feb 2022
Benjamin Thompson
on 1 Feb 2022
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])
>>
asdfa asdf
on 2 Feb 2022
Benjamin Thompson
on 2 Feb 2022
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.
Shinto Thomas
on 21 Dec 2023
Edited: Shinto Thomas
on 21 Dec 2023
How can I place the ports at bottom or top of the subsystem programatically, becasue side parameter has only two inputs left and right.
Categories
Find more on Event Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!