Matlab Introduction 1 Image and Multidimensional Signal Processing Colorado School of Mines

advertisement
Matlab Introduction
Colorado School of Mines
Image and Multidimensional Signal Processing
1
Matlab Introduction
• Overview
– “Matrix Laboratory”
– An interactive programming environment
– http://www.mathworks.com
• Availability
– On computers in Brown Hall (you need an “adit” logon)
– Can get student version low cost
• Why we are using
– Easy to prototype
– Powerful toolboxes such as the image processing toolbox
– Widely used; good help and documentation
Colorado School of Mines
Image and Multidimensional Signal Processing
2
Matlab
• Programming
–
–
–
–
Can type on command line, or use a program file (“m”-file)
Semicolon at end of line is optional (suppresses printing)
Control flow (if, for, etc) similar to C
Differences from C: no variable declarations, no pointers
• Help
– Browser - best source
– Command line
– Web (http://www.mathworks.com/help/matlab/index.html)
Colorado School of Mines
Image and Multidimensional Signal Processing
3
Matlab
• Everything is a matrix
– a variable is a 1x1 matrix
• Initializing a matrix:
– Example: my_matrix = [1 2 3; 4 5 6; 7 8 9];
• Accessing a matrix (row, column):
– my_matrix(1,2) has the value 2
• Colon operator generates a range
– Example: 1:10 = [1 2 3 4 5 6 7 8 9 10]
– mytest(1, 2:4) is equivalent to mytest(1,[2 3 4])
– mytest(3, :) refers to all elements of row 3
Colorado School of Mines
Image and Multidimensional Signal Processing
4
Matlab
• Built-in functions (exp, sin, log, etc)
• Variables
– whos (view all variables)
– clear all (Clear all variables )
• Types
– double (default)
– Also have integer, unsigned integer, logical, complex
• Expressions
–
–
–
–
+,-,/,*
Power is ^
Transpose is ‘ (apostrophe)
Period indicates point-by-point operation
• Plotting example (sin)
Colorado School of Mines
Image and Multidimensional Signal Processing
5
Examples
• Create matrix A and vector x
 1 2 3
 .1 


 
A =  4 5 6 , x =  .2 
7 8 9
 

 .3 

• Add 1 to each element of A
• Take the square root of each element of A
• Multiply A*x
• Create 3x4 matrix B by appending x to A
 1 2 3 .1 


B =  4 5 6 .2 
 7 8 9 .3 


• Show that (AB)T = BTAT
Colorado School of Mines
Image and Multidimensional Signal Processing
6
Related documents
Download