User-Defined function function output= my poly(x) This function calculates the value of a third-order comments - polynomial output=3*x^3+5*x^2-2*x+1 Save above commands into an M-file and then type the below commands in command window to observe the results ny poly(a) >>b=1:5; >>my poly (b) 12
User-Defined Function function output = my_poly(x) % This function calculates the value of a third-order % polynomial output = 3*x.^3+5*x.^2-2*x+1 Save above commands into an M-file and then type the below commands in command window to observe the results: >> a=4; >> my_poly(a) >> b=1:5; >> my_poly(b) comments 12
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
13 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
Objectives of Execution Control Why need execution control You may want to execute some parts of the code under certain circumstances only; You may want to repeat a section of code a certain number of times
14 Objectives of Execution Control • Why need execution control – You may want to execute some parts of the code under certain circumstances only; – You may want to repeat a section of code a certain number of times
Conditional execution General concept ots statements 15
15 Conditional Execution • General concepts • if statements
General Concepts Generally speaking, the statements written in our scripts have been executed in sequence from the top( the first line) to the bottom( the last line) However, it is frequently necessary to make choices about how to process a set of data based on some characteristic of that data
16 General Concepts • Generally speaking, the statements written in our scripts have been executed in sequence from the top (the first line) to the bottom (the last line). • However, it is frequently necessary to make choices about how to process a set of data based on some characteristic of that data