Is it possible to call a S-function with a return value in an other S-Function?

4 views (last 30 days)
Hello dear Matlab/Simulink User,
I am trying to make a Simulink Model out of C-Code. My Problem is, that i have nested functions in C. Let me try to explain like this: there is a function g(), that for example count how often it is called and returns the value, which should be static. Then this function g() is called in several other functions (f1(),f2(),f3()...). My problem is, that when i use the S-function builder the programm generates several instances of the function g() and the value for the variable count isn´t the same for the function f1(), f2(), f3()... My idea was to generate a s-function out of g() and use it in the s-functions of f1(),f2()...and create blocks out of it; is this possible?
Summary:
So what i need in simulink is the following case: during the simulation of one block jump to another block,run through it, get his outputvalue, jump back to the first block and work with the returned value
Does anybody know a solution or have a suggestion for my problem?
Thank you in advance!!!

Answers (1)

Kaustubha Govind
Kaustubha Govind on 19 Sep 2012
Unfortunately, S-functions can only be called by the Simulink Engine because they expect a SimStruct argument (S) that the Engine creates and maintains for each S-function - so you cannot call an S-function manually from another S-function. Did my previous suggestion of creating a static library out of g() not work?

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!