From: Timothy Tan on
Hi,

Just wondering what if I've got two separate s-functions. And I've
already initialized s-function 2, and only want to evaluate s-function
2 within s-function 1 as part of s-function 1 during MdlOutputs?

I can evaluate s-function 2 fine in the Matlab command prompt, just
not within another S-function.

Cheers

On Apr 30, 10:04 am, "Guy Rouleau" <guy.rouleau.nos...(a)mathworks.com>
wrote:
> "John Quincy" <q.joh...(a)gmail.com> wrote in message <hr9of1$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

From: Timothy Tan on
I should probably also mention that s-function 2 has been compiled to
a mex, was in Fortran prior.

Cheers,
Tim

On Jun 3, 5:05 pm, Timothy Tan <timothy....(a)gmail.com> wrote:
> Hi,
>
> Just wondering what if I've got two separate s-functions. And I've
> already initialized s-function 2, and only want to evaluate s-function
> 2 within s-function 1 as part of s-function 1 during MdlOutputs?
>
> I can evaluate s-function 2 fine in the Matlab command prompt, just
> not within another S-function.
>
> Cheers
>
> On Apr 30, 10:04 am, "Guy Rouleau" <guy.rouleau.nos...(a)mathworks.com>
> wrote:
>
>
>
> > "John Quincy" <q.joh...(a)gmail.com> wrote in message <hr9of1$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

From: Timothy Tan on
Hi there,

I've managed to do what I want now. Cheers,
Tim

On Jun 3, 5:13 pm, Timothy Tan <timothy....(a)gmail.com> wrote:
> I should probably also mention that s-function 2 has been compiled to
> a mex, was in Fortran prior.
>
> Cheers,
> Tim
>
> On Jun 3, 5:05 pm, Timothy Tan <timothy....(a)gmail.com> wrote:
>
>
>
> > Hi,
>
> > Just wondering what if I've got two separate s-functions. And I've
> > already initialized s-function 2, and only want to evaluate s-function
> > 2 within s-function 1 as part of s-function 1 during MdlOutputs?
>
> > I can evaluate s-function 2 fine in the Matlab command prompt, just
> > not within another S-function.
>
> > Cheers
>
> > On Apr 30, 10:04 am, "Guy Rouleau" <guy.rouleau.nos...(a)mathworks.com>
> > wrote:
>
> > > "John Quincy" <q.joh...(a)gmail.com> wrote in message <hr9of1$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