I would like to know what the difference is between the s function and the embedded MATLAB function in Simulink? Like when to use, etc. Can I use either one of them or is there any criteria?
S-function is system function usually written in C language, it needs to be compiled using some compiler registered with matlab (like VC), Embedded Matlab function is any script written in the form of m-file.
The main difference is that S-functions are compiled. Therefore, if you are running Simulink with the same solver, S-functions execute faster than embedded functions. Also, S-functions can be created using MATLAB compiler and mex interface, as well as an outside compiler, so you can code pretty much anything you want. The neat thing with an embedded function is that you can edit it since it's a MATLAB script. But there are limitations to what you can call inside the script. Not all MATLAB functions will work. If your concern is real-time execution, you should definitely use S-functions. If you want to be able to edit/modify code between executions, embedded functions are easier.
S-Function: It is similar to In-build function in c and user defined function are same as user defined function in Matlab. But in matlab you can see the code but in c or other language u cann't..