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

UDP Communication using Boost (for MATLAB s-function)

I'm trying to create an s-function (using C++ Boost library) for UDP communication. Implementing the sender was fairly straightforward, 15 min job. I'm struggling to get the receiver to work. I created the following in Visual Studio: #define…
Neal
  • 3
  • 2
0
votes
0 answers

Arduino for Simulink/MatLAB -- S-Function does not exist

I'm trying to run a simple SimuLink code, and everything has started to act strangely. It's a basic program: take constant -> Send to PWM block. I'm getting error in the command window: "Warning: Could not evaluate MaskDisplay commands of block…
GrantG
  • 43
  • 3
0
votes
0 answers

Output structure-array from c-mex s-functions

I am trying to output the following structure via a bus-object in simulink from my c-mex s-function. The following code-snippet is from my main matlab-file and if I run this script, the slBus1-simulink-bus-object is created and placed in the…
Lemonbonbon
  • 686
  • 5
  • 25
0
votes
2 answers

Static Variables in Simulink S-Function Builder

I am currently working on the implementation of some C-Code in a Simulink model using the S-Function Builder block. The code uses various timers and counters, which are defined as static variables to enable the access to the data in following…
J.M.
  • 25
  • 9
0
votes
2 answers

Get variable in S Function from Workspace

I would like to get variable in S-Function (.cpp and wrapper.cpp) from workspace of Matlab. How can I do that? Thanks.
Smith
  • 33
  • 7
0
votes
0 answers

Set different path headers in S function Matlab

I would like to set paths headers in S function in Matlab to do that Matlab goes to those paths to find headers. I give an example: header 1 in path 1 (current folder matlab) header 2 in path 2 header 3 in path 2 I call headers in S Function code…
Smith
  • 33
  • 7
0
votes
0 answers

Compiling C S-Function in MATLAB multiple definition error

I am trying to compile various C-Functions in MATLAB Simulink using the S-function builder block and the minGW 64bit Compiler. A syntax error in the code is impossible since it is code from an ECU which is in production and running for years. I keep…
J.M.
  • 25
  • 9
0
votes
2 answers

Matab tlc code for s-functions having multiple instances

i need to inline an s-function having multiple instances in my simulink model. In S-function, i need to load a dll file but it should be done in only one instance of s-function. I wrote tlc as follows : ..... % function Start(block, system)…
0
votes
2 answers

set initial conditions in matlab function block (simulink)

I'm currently trying to learn some basis for a bigger project that will make a massive use of simulink. Right now, I would like to code my own simulink block whith a feedback. It means that one of the inputs is also the output (with a 'memory'…
Ezor
  • 135
  • 2
  • 18
0
votes
1 answer

Masking Simulink blocks: how to interpret mask parameter as string?

when I'm masking a block (in this case putting a mask on an sfunction) I want one of the parameters to be treated as a literal string. I know to use 'unit8(sParameter1)' but I can't figure out how to change that line to make it a string. And I want…
0
votes
0 answers

Add inports & outports to Simulink C Mex S-Function mask

I am trying to amend the example given here for creating a dynamic masked subsystem, where I want to dynamically change the number of imports and outports to an S-Function. I have a very simple S-Function implemented in C (it's the timestwo example…
John
  • 10,837
  • 17
  • 78
  • 141
0
votes
1 answer

Passing a structure of parameters to a Level 1 m-code S-function in Simulink

I am trying to pass a structure of parameters to an S-function in MATLAB. I have a bunch of parameters and I would like to avoid passing them like this: % The general form of an MATLAB S-function syntax is: % …
0
votes
0 answers

Matlab S-Function (Compiled with VS 2013) - Error while obtaining sizes (...) could not find procedure

When I try to run my simulation I get error from S-function: Error while obtaining sizes from MEX S-function 'sfunction' in 'test/S-Function'. Caused by: Invalid MEX-file ($PATH)\sfunction.mexw64': Could not find procedure. My debug…
user1598527
  • 5
  • 1
  • 8
0
votes
1 answer

Matlab S-function builder with Visual Studio 2013 - missing rtwtypes.h

I'm trying to compile pre-generated code from Simulink S-function builder and I get an error: fatal error C1083: Cannot open include file: 'rtwtypes.h': No such file or directory I've gone trough every include directory in matlab and simulink and…
user1598527
  • 5
  • 1
  • 8
0
votes
1 answer

why datatype in simulink c s function is different from normal c datatype

In simulink c s function examples int_T and real_T are used as datatype . If I change them to double and int it will work fine , then what is the reason to use int_T and real_T as suggested in examples?
redumpt
  • 167
  • 13
1 2 3
8 9