Questions tagged [s-function]

S-functions (system-functions) provide a powerful mechanism for extending the capabilities of the Simulink® environment. An S-function is a computer language description of a Simulink block written in MATLAB®, C, C++, or Fortran. By following a set of simple rules, you can implement an algorithm in an S-function and use the S-Function block to add it to a Simulink model.

Taken from MathWorks:

S-functions (system-functions) provide a powerful mechanism for extending the capabilities of the Simulink® environment. An S-function is a computer language description of a Simulink block written in MATLAB®, C, C++, or Fortran. C, C++, and Fortran S-functions are compiled as MEX files using the mex utility (see Build MEX-File). As with other MEX files, S-functions are dynamically linked subroutines that the MATLAB interpreter can automatically load and execute.

S-functions use a special calling syntax called the S-function API that enables you to interact with the Simulink engine. This interaction is very similar to the interaction that takes place between the engine and built-in Simulink blocks.

S-functions follow a general form and can accommodate continuous, discrete, and hybrid systems. By following a set of simple rules, you can implement an algorithm in an S-function and use the S-Function block to add it to a Simulink model. After you write your S-function and place its name in an S-Function block (available in the User-Defined Functions block library), you can customize the user interface using masking (see What Are Masks?).

If you have Simulink Coder™, you can use S-functions with the software. You can also customize the code generated for S-functions by writing a Target Language Compiler (TLC) file. For more information, see Insert S-Function Code.

131 questions
0
votes
1 answer

How to get array size input using S-function builder

I am using MATLAB2014b s-function builder and I would like to get the size of my input array. For example, I have the following input. Name: A, dimension: 2, Row: 1, Column: 16, Real In the output pane, I wrote the following code in order to get the…
oro777
  • 1,110
  • 1
  • 14
  • 29
0
votes
1 answer

What is void** in a S-Function .cpp

I am reading some code written in a .cpp file on which is based a MATLAB S-Function. I just want to know what does it mean : void** vecPWork Is it a variable of which type? And the two stars stand for what? thanks for your time.
desmond13
  • 2,913
  • 3
  • 29
  • 46
0
votes
2 answers

How to use a variable as parameter of a s-function in simulink

I want specify some parameters of a s-functions using a variable and not using a constant inserted manually. I have tried to define global variables in matlab and using them as paramaters and it works fine. Anyway, i want that a variable computed…
Antonio
  • 29
  • 5
0
votes
1 answer

In Simulink, does mdlUpdate count as Direct Feedthrough too?

I have an input port to my CMEX S-Function that I set to NOT have Direct Feedthrough. However, when I try to use the signal from the input port in the mdlUpdate function call, it crashes with Segmentation Violation and informs me that the most…
user2215426
0
votes
0 answers

How do I tackle the artificial algebraic loops that Simulink detects?

This is a bit of a convoluted problem that deals with a slightly open ended question. I realize that StackOverflow frowns on this practice, but as you will see, it is hard for me to break it down into smaller parts. I have C++ code that is called…
user2215426
0
votes
2 answers

display a Simulink current simulation time

folks! I am trying to display the Simulink current simulation time. I have to notice that, in my case, the system is not viewable, once I use load_system, and it would be very useful to know how progress the simulation. For that, I have read that I…
Agaeme
  • 13
  • 1
  • 4
0
votes
1 answer

Simulink: How to use a local variable in a level 2 s-function?

I have written a Simulink S-function (Level 2) in C. The resulting block has one output and one parameter. This parameter is stored in a variable, which is defined at file scope, right after setting up the block: #define NUM_PARAMS 1 #define…
Flo
  • 219
  • 2
  • 10
0
votes
1 answer

S function for 2 D look up Table, Similar to "sfix_look1_dyn.mex32"

I need some information about "sfix_look1_dyn.mex32" file. Currently I am using this mex file, with the help of masked s function block. I am using this block only for 1 D look up related calculations. But if I want to use similar kind of logic for…
0
votes
1 answer

Simulink SFunction Builder Bus input value

I'm trying to understand how to access and use the Bus system with custom S-Function Blocks. I built a very basic S-Function using the S-Function Builder which has no input and one Bus output. The Bus is a struct consisting only of one field of type…
Roberto
  • 713
  • 8
  • 14
0
votes
0 answers

How to vectorize a part of a Level 2 S function

I'm working with the Matlab's level 2 Functions within a Simulink block diagram to send serial data to an Arduino Board, which has to move 11 servos of a robot. I'm trying to improve the speed of the Simulation by vectorizing the assignment of the…
Charlie
  • 252
  • 5
  • 16
0
votes
1 answer

Matlab Simulink S-Function: How to transfer the data from block to block except using a global variable

In my Simulink model, I have many Block S-Functions sharing a global variable. As we know, the value of the global variable will be transferred and possibly changed from block to block. I wonder if there is an alternative to transfer the data from…
user3518207
  • 21
  • 1
  • 3
0
votes
1 answer

clear all from Simulink S-function

I am trying to call clear all from a simulink Level 1 S-function. I've take a look over doc mexCallMATLAB but I do not know how to use it. I've wanted to clear the work space after my function is called.
0
votes
1 answer

What's the relationship between the time step size of an individuell block and that of the system?

As we know, a level 2 Matlab S Function has a command to accquire the next hit time for its block like: block.NextTimeHit = block.CurrentTime + deltaT; What's the relationship between the time step size of an individuell block and that of the…
user3518207
  • 21
  • 1
  • 3
0
votes
1 answer

Wait using s-function

I am using a s-function built in Simulink and I need to implement a waiting time. For example I need to do this : send the first frame wait 20 ms send the second frame wait 20 ms send third frame How could I establish this waiting time between…
0
votes
1 answer

Waiting time in S-function

I am trying to create a flashing procedure in Simulink using a S-function (C language) and I need to send some frames and the time between 2 consecutive frames should be lets say 200 milisconds. How can I implement this waiting time? Is there any…
1 2 3
8
9