Search code examples
matlabsimulinks-function

how to create a custom s-function in simulink?


What is the block that I can use for the creating a custom s-function in simulink?

I want to use C code using S-Function.. I know that there are functions that I have to define but I don't know how to reach it or which code to start with exactly..

Note: I am totally new to matlab and simulink..


Solution

  • Check out the S-function Builder block from Simulink's library (in Simulink->User Defined Functions). You can set number of states, inputs, outputs and also add code for calculating the derivatives + outputs. When you press Build it generates C code and you can start with that as a template. Or you could use the S-function Builder interface for writing all your code.

    Edit: Matlab also has a built-in template that you can access:

    edit([matlabroot,'/simulink/src/sfuntmpl_basic.c']);