Positioning Subsystem Ports in Simulink/Simscape via MATLAB Code (LConn / RConn)
Dear Community,
I’m currently working on my master’s thesis and attempting to create a Simulink/Simscape model directly from MATLAB. I aim to consolidate certain "Building Blocks" that are used repeatedly into a subsystem for the sake of clarity. My goal is to position the ports of this subsystem directly from MATLAB.
Presently, I have a result that looks similar to the attached image.
However, I wish to rearrange the ports, all of which are currently situated on the left side of the subsystem, so that they are positioned as follows (Manual Post-Processing Performed):
In my attempts thus far, I’ve encountered the issue that the ports are set as "read-only," preventing me from defining their positions. I’ve tried to set the position as follows:
subsystem_block = "path_to_subsystem"
port_handles = get_param(subsystem_block, ‘PortHandles’)
N = length(port_handles.LConn)
newx = 1:N % example
newy = 1:N % example
for k = 1:N
set_param(port_handles.LConn(i), ‘Position’, [newx(k), newy(k)]);
end
Unfortunately, this yields the error message "Port parameter ‘Position’ is read-only."
Is there a way to set the position of the ports of the subsystem directly from MATLAB? If so, could someone explain how to do it? If not, what alternatives would I have if I still want to utilize a sort of "Building Block"?
Any assistance would be greatly appreciated!Dear Community,
I’m currently working on my master’s thesis and attempting to create a Simulink/Simscape model directly from MATLAB. I aim to consolidate certain "Building Blocks" that are used repeatedly into a subsystem for the sake of clarity. My goal is to position the ports of this subsystem directly from MATLAB.
Presently, I have a result that looks similar to the attached image.
However, I wish to rearrange the ports, all of which are currently situated on the left side of the subsystem, so that they are positioned as follows (Manual Post-Processing Performed):
In my attempts thus far, I’ve encountered the issue that the ports are set as "read-only," preventing me from defining their positions. I’ve tried to set the position as follows:
subsystem_block = "path_to_subsystem"
port_handles = get_param(subsystem_block, ‘PortHandles’)
N = length(port_handles.LConn)
newx = 1:N % example
newy = 1:N % example
for k = 1:N
set_param(port_handles.LConn(i), ‘Position’, [newx(k), newy(k)]);
end
Unfortunately, this yields the error message "Port parameter ‘Position’ is read-only."
Is there a way to set the position of the ports of the subsystem directly from MATLAB? If so, could someone explain how to do it? If not, what alternatives would I have if I still want to utilize a sort of "Building Block"?
Any assistance would be greatly appreciated! Dear Community,
I’m currently working on my master’s thesis and attempting to create a Simulink/Simscape model directly from MATLAB. I aim to consolidate certain "Building Blocks" that are used repeatedly into a subsystem for the sake of clarity. My goal is to position the ports of this subsystem directly from MATLAB.
Presently, I have a result that looks similar to the attached image.
However, I wish to rearrange the ports, all of which are currently situated on the left side of the subsystem, so that they are positioned as follows (Manual Post-Processing Performed):
In my attempts thus far, I’ve encountered the issue that the ports are set as "read-only," preventing me from defining their positions. I’ve tried to set the position as follows:
subsystem_block = "path_to_subsystem"
port_handles = get_param(subsystem_block, ‘PortHandles’)
N = length(port_handles.LConn)
newx = 1:N % example
newy = 1:N % example
for k = 1:N
set_param(port_handles.LConn(i), ‘Position’, [newx(k), newy(k)]);
end
Unfortunately, this yields the error message "Port parameter ‘Position’ is read-only."
Is there a way to set the position of the ports of the subsystem directly from MATLAB? If so, could someone explain how to do it? If not, what alternatives would I have if I still want to utilize a sort of "Building Block"?
Any assistance would be greatly appreciated! simscape, simulink, create simulink model from matlab MATLAB Answers — New Questions