tailieunhanh - Lecture Data visualization - Chapter 28

The main contents of the chapter consist of the following: Functions with no input or no output, determining the number of input and output arguments, local variables, global variables, creating toolbox of functions, anonymous functions and function handles, function functions, subfunctions. | Lecture 28 Recap Functions with No input OR No output Determining The Number of Input and Output Arguments Local Variables Global Variables Creating ToolBox of Functions Anonymous Functions and Function Handles Function Functions Subfunctions Summary of Chapter MATLAB contains a wide variety of built-in functions However, you will often find it useful to create your own MATLAB functions The most common type of user-defined MATLAB function is the function M-file, which must start with a function-definition line that contains the word function a variable that defines the function output a function name a variable used for the input argument For example, function output = my_function(x) Continued . The function name must also be the name of the M-file in which the function is stored Function names follow the standard MATLAB naming rules Like the built-in functions, user-defined functions can accept multiple inputs and can return multiple results Comments immediately following the function-definition line can be accessed from the command window with the help command Variables defined within a function are local to that function. They are not stored in the workspace and cannot be accessed from the command window Global variables can be defined with the global command used in both the command window and a MATLAB function. Good programming style suggests that define global variables with capital letters. In general, however, it is not wise to use global variables Continued . Groups of user-defined functions, called “toolboxes,” may be stored in a common directory and accessed by modifying the MATLAB® search path. This is accomplished interactively with the path tool, either from the menu bar, as in File -> Set Path or from the command line, with pathtool MATLAB provides access to numerous toolboxes developed at The MathWorks or by the user community Another type of function is the anonymous function, which is defined in a MATLAB session or in a script M-file and exists . | Lecture 28 Recap Functions with No input OR No output Determining The Number of Input and Output Arguments Local Variables Global Variables Creating ToolBox of Functions Anonymous Functions and Function Handles Function Functions Subfunctions Summary of Chapter MATLAB contains a wide variety of built-in functions However, you will often find it useful to create your own MATLAB functions The most common type of user-defined MATLAB function is the function M-file, which must start with a function-definition line that contains the word function a variable that defines the function output a function name a variable used for the input argument For example, function output = my_function(x) Continued . The function name must also be the name of the M-file in which the function is stored Function names follow the standard MATLAB naming rules Like the built-in functions, user-defined functions can accept multiple inputs and can return multiple results Comments immediately following the .