From: John Quincy on
This question might not make sense, I am still a beginner. Is it possible to call an s-function from inside another s-function. Say when calculating my output I want to call one s-function in my input is something and another if the input is something else. Would something like this be possible or am I going about this the wrong way.

Thanks,
From: Guy Rouleau on
"John Quincy" <q.john92(a)gmail.com> wrote in message <hr9of1$1g$1(a)fred.mathworks.com>...
> This question might not make sense, I am still a beginner. Is it possible to call an s-function from inside another s-function. Say when calculating my output I want to call one s-function in my input is something and another if the input is something else. Would something like this be possible or am I going about this the wrong way.
>
> Thanks,

Hi,

I would vote for the wrong way ;-)

If you want to execute a different computation based on an input signal value, I would either:

- Implement 2 s-functions. You can then select the one to use by placing them in If action subsystems or just using a switch block.

- Implement 1 s-function and use an IF statement in your s-function code (probably in MdlOutputs and maybe also in MdlDerivative and MdlUpdate). This approach might be easier if your s-function has states.

Also, if what you want is not calling "an -sfunction inside and s-function" but calling legacy code from an s-function, then you might want to look at the S-function Builder block or the Legacy code Tool.

HTH,
Guy