Level II S-function input=output ports are not apearing
Afficher commentaires plus anciens
Hi everyone,
I am using an level II S-Function to send the position of a robot from Simulink to the MATLAB workspace. In the workspace, a controller computes the appropriate control commands and sends them back to Simulink via another Level-2 S-Function.
In the second S-Function, which is responsible for sending the computed control commands from the workspace to Simulink, I have defined two output ports and zero input ports. However, the Simulink block shows a single input port (due to the argument block) and no output ports.
Can someone explain what I should do to make the output ports visible?
I enclosed the picture of the block in Simulink.
(I am using 2019b release)
Thanks in advance
Here is my code for the second Level-2 S-Function:
function getThrust(block)
setup(block);
end
function setup(block)
block.NumInputPorts = 0
block.NumOutputPorts = 2
block.OutputPort(1).Dimensions = 4;
block.OutputPort(2).Dimensions = 4;
block.OutputPort(1).Complexity = 'Real';
block.OutputPort(2).Complexity = 'Real';
block.OutputPort(1).DatatypeID = 0;
block.OutputPort(2).DatatypeID = 0;
block.SampleTimes = [0.1 0]; % stepping time of 0.1 [sec.]
block.RegBlockMethod('Outputs',@Outputs);
end
function Outputs(block)
try
RPM_in = evalin('base', 'thrusterPower');
catch
RPM_in = zeros(1,4);
end
try
alpha_in = evalin('base', 'thrusterAngles')
catch
angles = zeros(1,4);
end
RPM_in = reshape(RPM_in, [1,4]);
alpha_in = reshape(alpha_in, [1,4]);
block.OutputPort(1).Data = RPM_in;
block.OutputPort(2).Data = alpha_in;
end

2 commentaires
Aabha
le 11 Fév 2025
I tried using the code you have provided for the Level-2 MATLAB S-Function, but I don’t seem to face this issue. Here are the steps I followed:
- Created a MATLAB Script titled “getThrust.m” and copied the code you have provided into it.
- Created a blank Simulink Model in the same directory as the “getThrust.m” file and added a “Level-2 MATLAB S-Function” block. In the block parameters, I specified the file name “getThrust” in the “S-Function name” dialog.
After updating the model, I can see the S-Function block with 0 input ports and 2 output ports as specified.

There might be some other issue in the model that is causing this.
mehrzad
le 13 Fév 2025
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Simulink dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!