Review of lab 2 about m file Open the m-files and run it E Editor-J:starry\code\sub plot. m File Edit Text Go Cell Tools Debug Desktop window Help |哈0|公·付⊙②日省省即追 冒唱-1.0+÷1.1 Run sub plot. m (F 0:pi/20:2*pi olot (x subplot(2, 1, 2) 5- plot (x, sin(2*x)) mypolymx Untitled. m x sub _plot. m x n 1 Col 1 OVRI
7 Review of Lab 2 about M file • Open the M-file’s and run it
Outline of lab 3 1. Review of lab 2 2. User defined function 3. Execution control 4. Plots and graphs using Matlab 5. Basic manipulation in image processing 6. Color image compression
8 Outline of Lab 3 1. Review of Lab 2 2. User defined function 3. Execution control 4. Plots and graphs using Matlab 5. Basic manipulation in image processing 6. Color image compression
User-Defined Function A function is a piece of computer code that accepts ar input argument from the user and provides output to th ne program You may wish to define your own functions-those which are used commonly in your programming User-defined functions are stored as m-files and can be accessed by Matlab if they are in the current directory
User-Defined Function • A function is a piece of computer code that accepts an input argument from the user and provides output to the program. You may wish to define your own functions-those which are used commonly in your programming. User-defined functions are stored as M-files and can be accessed by Matlab if they are in the current directory. 9
User-Defined Function Each function consists of a name, user-provided input and calculated output. For example, the function my function (x) Is named my function, takes user input inside the parentheses(in this case, x), and calculate a result The user does not see the calculations performed but just accepts the answer. The function could be regarded as a black box Input output function
User-Defined Function • Each function consists of a name, user-provided input, and calculated output. For example, the function: my_function(x) – is named my_function, – takes user input inside the parentheses (in this case, x), and – calculate a result. • The user does not see the calculations performed, but just accepts the answer. The function could be regarded as a black box. input output function 10
User-Defined Function User-defined functions are stored as m-files. each must start with a function definition line that contains the word " function one or several variables that defines the function output a function name and one or several variables used for the input argument Save the function as M-file using the same name in your function · Some examples function output=my function(x) function [outputl, output2]=my function(x1, x2, 3) Hints: The function name and the names of the input and output variables are arbitrary and selected by the programmer, but the word function can not be changed
User-Defined Function • User-defined functions are stored as M-files. Each must start with a function definition line that contains ➢ the word “function”, ➢ one or several variables that defines the function output, ➢ a function name, and ➢ one or several variables used for the input argument. ➢ Save the function as M-file using the same name in your function • Some examples: • function output = my_function(x) • function [output1, output2] = my_function(x1,x2,x3) • Hints: The function name and the names of the input and output variables are arbitrary and selected by the programmer, but the word “function” can not be changed. 11