user1413188
user1413188

Reputation: 101

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..

Upvotes: 2

Views: 6068

Answers (2)

remus
remus

Reputation: 2710

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']);

Upvotes: 4

sebastian
sebastian

Reputation: 9696

Did you check the MATLAB documentation on this? It is usually pretty complete, once you find the right page to read.

For s-functions there e.g. is

http://www.mathworks.de/de/help/simulink/sfg/how-to-implement-s-functions.html

which includes links to example s-functions you can find in your matlab-installation.

Upvotes: 3

Related Questions