MATLAB function file knowledge summary

1. The basic structure of matlab function file:

Its structure is shown in the figure below:
Insert picture description here
Personal suggestion: The function name and the function file name should be the same as possible. But it's okay if it's different. When the two are different, MATLAB will ignore the function name and confirm the function file name, so the function file name is used when calling the function

2. Annotation of the function

Good and standardized notes can improve the readability of the code, thereby improving the efficiency of writers and users.
Generally, the comment immediately following the first line of the function represents the summary content of the function, and the next part is the detailed description of the function. Use "help function name" to query the description content in front of the function body.

3. Function call

After the function is compiled, it can be called in a fixed format. The general format is:
[output actual parameter list]=function name (input formal parameter list)
! ! ! Note that the actual parameters and formal parameters in the written function must have a one-to-one correspondence to the function to run smoothly, otherwise an error will be reported.

You can also call nested calls in matlab: a function can call other functions, or it can call itself. Call another function multiple times in one function, and the expected return value is different

Guess you like

Origin blog.csdn.net/weixin_45915507/article/details/105586278