tailieunhanh - Lecture Data visualization - Chapter 26

This chapter presents the following content: Basic definitions, example of a database, typical DBMS functionality, main characteristics of the database approach, database users, workers behind the scene,. | Lecture 26 Recap Saving Plots Summary of Chapter 5 Introduction of Chapter 6 Function M-files User-defined functions are stored as M-files and can be accessed by MATLAB if they are in the current folder or on MATLAB’s search path Syntax of Function M-file Both built-in MATLAB ® functions and user-defined MATLAB functions have the same structure Each consists of a name, user-provided input, and calculated output. For example: the function cos(x) is named cos takes the user input inside the parentheses (in this case, x ) calculates a result The user does not see the calculations performed, but just accepts the answer User-defined functions work the same way Imagine that you have created a function called my_function Using my_function(x) in a program or from the command window will return a result, as long as x is defined and the logic in the function definition works Continued . User-defined functions are created in M-fi les. Each 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) is the first line of the user-defined function called my_function It requires one input argument, which the program will call x , and will calculate one output argument, which the program will call output The function name and the names of the input and output variables are arbitrary and are selected by the programmer Here’s an example of an appropriate fi rst line for a function called calculation : function result = calculation(a) In this case, the function name is calculation , the input argument will be called a in any calculations performed in the function program, and the output will be called result Although any valid MATLAB ® names can be used, it is good programming practice to use meaningful names for all variables and for function names Continued . Here’s an example of a very simple MATLAB function that . | Lecture 26 Recap Saving Plots Summary of Chapter 5 Introduction of Chapter 6 Function M-files User-defined functions are stored as M-files and can be accessed by MATLAB if they are in the current folder or on MATLAB’s search path Syntax of Function M-file Both built-in MATLAB ® functions and user-defined MATLAB functions have the same structure Each consists of a name, user-provided input, and calculated output. For example: the function cos(x) is named cos takes the user input inside the parentheses (in this case, x ) calculates a result The user does not see the calculations performed, but just accepts the answer User-defined functions work the same way Imagine that you have created a function called my_function Using my_function(x) in a program or from the command window will return a result, as long as x is defined and the logic in the function definition works Continued . User-defined functions are created in M-fi les. Each must start with a function-definition line that .