Current location - Education and Training Encyclopedia - Graduation thesis - Simulink! Is there a difference between the functions in matlab user-defined functions?
Simulink! Is there a difference between the functions in matlab user-defined functions?
There are several user-defined functional modules in Simulink:

Fcn: Suitable for simple expressions. Simple does not necessarily mean that the expression is short, but that the relationship between input and output can be directly described by an expression, that is, neither state nor process control is used. It should be noted that the functions available in the expression are limited (basically some simple mathematical functions). C code can be generated.

MATLAB Fcn: Maybe many people have a good grasp of this module. This module corresponds to an M file, and the input signal can be output after any processing. You can use any function of MATLAB. There are two main limitations: (1) can't generate code, so people who are going to do control prototype or hardware-in-the-loop simulation should try to avoid using it; (2) In principle, state variables cannot be used, that is to say, only the input at the current moment can be calculated and processed to get the output, and the information at the previous moment cannot be used-if the information at the previous moment needs to be used, other external modules (such as integrators or unit delays) generally need to be used together.

Embedded MATLAB Fcn: Similar to MATLAB Fcn, the differences are as follows: (1) can generate C code; (2) The requirements are much stricter than MATLAB Fcn, and many functions or toolboxes are not allowed to be used in EMF (due to the limitation of code generation); (3) The module itself supports multiple inputs and multiple outputs.

S-Function: This is the most difficult and powerful custom module of Simulink, and it can be used to realize the functions of any module of Simulink in principle. The biggest difference between the S function and the previous module is that it can use states. According to the simulation process, the code is divided into several parts: initialization, calculating derivatives (integration is completed by Simulink system), updating states, calculating output, and terminating processing (calling several of them periodically during the simulation process), which gives users great freedom to organize the code. S function can be realized in C language or M language, and M language has different levels. There are corresponding templates and examples for writing S functions, and it takes some time to understand if you want to learn.

A little personal experience, while thinking and writing, is not guaranteed to be absolutely accurate, but there should be no big mistakes and omissions. I hope it will help the landlord.