Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Mex Function - specifying an input to output port dependency

Asked by Mark on 18 Oct 2012

I'd like to be able to specify an input port to output port dependency on my mex function Simulink blocks to that Simulink doesn't falsely think there are algebraic loops. Is this possible? Could it be made possible?

For example, for some of my blocks there's a simple input to output port relationship (output port N is dependent only on input port N), If any output port loops back without a delay (e.g. output port M loops back through combinational logic to input port P, ( P != M)), Simulink will think this is an algebraic loop, as it will assume all input ports to the block drive all outputs (for this example that there is a connection from P to M in the block). I want to tell Simulink there is no such connection and therefore no loop by specifying some internal connectivity relationship for my block.

0 Comments

Mark

Products

1 Answer

Answer by Kaustubha Govind on 18 Oct 2012

I've not tried this myself, but if the input port P is not used directly in the mdlOutputs method (can be used in mdlUpdate instead), I think you can set ssSetInputPortDirectFeedThrough to zero for that port to avoid algebraic loops.

2 Comments

Mark on 18 Oct 2012

Thanks for the answer. I thought ssSetInputPortDirectFeedThrough was more about whether there is any simulation delay across the block from a particular input port to any output port. In my case there is direct feed-through for input port 0 -> output port 0, and indeed for input port 1 -> output port 1, etc., but not for input port 0 -> input port 1. I want to tell Simulink this, so that if I loop back output 1 to input 0 it won't complain about an algebraic loop through my mex function; but if I loop it back to input 1 it will. What I need is some function which takes both an input port and an output port as parameters so I could do something like:

ssSetInputToOutputDirectFeedThrough(S, inPort0, outPort0, 1); ssSetInputToOutputDirectFeedThrough(S, inPort0, outPort1, 0);

Kaustubha Govind on 22 Oct 2012

Mark: I'm trying to think if such an API function would make sense considering that there is only one mdlOutputs function to compute all the outputs - not sure if what you're asking for might violate some of the Simulink Engine's rules. Perhaps if it is possible, you could split your functionality into two S-function blocks and combine them into one (virtual) subsystem? So to a user, it will still be one block, but you are separating out the implementation.

Please feel free to contact MathWorks Tech Support to verify if there is a better solution, and to submit an enhancement request with your requirements.

Kaustubha Govind

Contact us