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.

125 questions
4
votes
0 answers

Matlab: S-Function Builder Block: Distribute source files across multiple paths

To build to target hardware, an an S-function Builder block requires access to its source files and .mex file. It seems that the source files and the .mex file MUST be in the same directory on the Matlab path. Is it possible to place distribute the…
kando
  • 391
  • 1
  • 14
4
votes
0 answers

Matlab C++ S-Function with multiple source files

I have a simulink model with a c++ s-function. This s-function needs access to a lot of (>50) classes. Each class is consists of a header (.h) and a source (.cpp) file. I have also divided my code into multiple…
Gustav-Gans
  • 305
  • 1
  • 3
  • 12
2
votes
0 answers

Passing a string array as parameter in s-function

I'm creating a C++ mex function using the S-function builder option in simulink (matlab). I've successfully captured strings passed as a dialog box parameter in Simulink as: Simulink block dialog: Parameter : uint8('This is a…
magni
  • 21
  • 1
2
votes
1 answer

Why char is stored as 2 bytes in Matlab S-Function

I would like to pass an uint8 array to my S-Function as a parameter: inParam = char(uint8(1:7)) In the S-Function I did the followings UINT8_T *inParam = (UINT8_T *)mxGetPr(ssGetSFcnParam(S, PARAM_IN_PORT_NR)); //; but I saw that actually the…
OHLÁLÁ
  • 9,372
  • 18
  • 75
  • 118
2
votes
1 answer

How to read Bus object into C struct inside C S-Function [Matlab]

I have defined a Bus object in Matlab and I am passing it to a C S-function that will do some processing. I have initialized the input like this inside mdlInitializeSizes: #if defined(MATLAB_MEX_FILE) if (ssGetSimMode(S) !=…
user1011113
  • 537
  • 2
  • 15
2
votes
0 answers

SFunction memory violation

I am writting a S Function that outputs a array of boolean (4 positions) I am having a access memmory violation while writing the outputs inside mdlOutputs callback. This error is not instantenous. I mean: the code runs fine until it crashes later…
guilhermecgs
  • 2,520
  • 8
  • 30
  • 53
2
votes
0 answers

how to change the s-function data using command line

can anyone tell me how to change the s-function parameters using the command line. i used the following lines to get the s-function data: blkNames = find_system(system,'lookundermasks','all','BlockType','S-Function'); blkHandle =…
Arun Kumar
  • 103
  • 9
2
votes
0 answers

Matlab/Simulink - Dymola Interface. Dymolablock out of Date

I'm trying to create a compound model of Matlab and Dymola. Therefore I followed this tutorial: Claytex tutorial Instead of the DrivenPendulum model, I made a simple model myself. I can translate the model in Dymola just fine, and the Compilation of…
EBC_Magnus
  • 41
  • 3
2
votes
1 answer

How to determine input sequence in c-mex s-function?

I am implementing a c-mex sfunction in simulink for accelerating the multiplication of two matrices. So far it is working, but I found out that the input ordering/sequence is depended of the naming schema of the connected e.g. constants. I attached…
steffenmauch
  • 251
  • 4
  • 15
2
votes
0 answers

how to get the parameters from s-function block in legacy code tool

i am working on tunable parameters and with a manual s-function its pretty straight forward. but what to do when we want to make variables tunable (getting them as parameters from s-function parameter block ) and generating the s-function…
Arun Kumar
  • 103
  • 9
2
votes
1 answer

Memory block alternative that ISN'T fixed in minor time step?

I have a model with some inputs that are fed into a CMEX S-Function via the Memory block, and the S-Function provides outputs based on these inputs, and those inputs are fed back into the S-Function. Classic algebraic loop scenario. I was using a…
user2215426
2
votes
1 answer

Pass Simulink.Parameter to C S-function

How does one pass a Simulink.Parameter structure (which, in my case, is a structure of structures) to a C S-function? Edit: Information on Simulink.Parameter You can create a Simulink.Parameter object this way: modelParameters =…
remus
  • 2,525
  • 2
  • 17
  • 43
2
votes
1 answer

Dynamically sized bus objects in Simulink

I wrote a C S function which has a variable number of states depending on one parameter, which is passed to it (I'm using computational fluid dynamics and the parameter is the number of cells). I want to output a bus object from my S function that…
remus
  • 2,525
  • 2
  • 17
  • 43
1
vote
0 answers

Remove HTTP headers and parse JSON payload in C with tiny-json (no libcurl)

As above, I'm trying to manage HTTP response with JSON payload without any library like curl or others. Everything is written inside an S-function in Simulink environment but the "main" is (hoping) perfectly C. My procedure: take the uint8 array…
nick_bl
  • 13
  • 2
1
vote
1 answer

C file not instrumented for coverage, bad expr node kind

I am using the legacy_code tool in MATLAB, to generate some S Functions, then I want the S Functions to be under analysis by the simulink coverage toolbox. I am asking also here because maybe this is a C issue and not MATLAB related. I am setting to…
Luis
  • 127
  • 11
1
2 3
8 9