lecture 6 sept 15, 09 goals: two-dimensional arrays matrix operations circuit analysis using matlab...
Post on 21-Dec-2015
217 views
TRANSCRIPT
![Page 1: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/1.jpg)
Lecture 6 Sept 15, 09
Goals:
• two-dimensional arrays
• matrix operations
• circuit analysis using Matlab
• image processing – simple examples
![Page 2: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/2.jpg)
4.2. Matrices
Example: The following 2 x 3 matrix (matA) can be created in Matlab as follows:
Dimension of a matrix can be accessed by function called size.
![Page 3: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/3.jpg)
Accessing and modifying array elements
![Page 4: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/4.jpg)
Accessing and modifying array elements
![Page 5: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/5.jpg)
Accessing and modifying array elements
![Page 6: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/6.jpg)
Matrix operationsMatrix addition, multiplication, inverse, determinant etc.
![Page 7: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/7.jpg)
Matrix operationsMatrix addition, multiplication, inverse, determinant, transpose etc.
![Page 8: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/8.jpg)
Logical indexing in 2-dim matrices
![Page 9: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/9.jpg)
![Page 10: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/10.jpg)
Exercise: Solve a linear system of equations: 3x + 5y – 6z= 11 4x – 6y + z = 9 -2x + 3y + 5z = –13
![Page 11: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/11.jpg)
Example 2
![Page 12: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/12.jpg)
![Page 13: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/13.jpg)
Sum, max, min, size etc.
![Page 14: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/14.jpg)
4.3. Mixed Data Types
Structure is variable that can hold a group of data (of different types).
Example:
![Page 15: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/15.jpg)
Array of structuresExample:
![Page 16: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/16.jpg)
Cell arrays
A cell array is like a vector, except that each member need not be all of the same type.
![Page 17: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/17.jpg)
Images as arrays
![Page 18: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/18.jpg)
Images as arrays
Numerical representation of array (gray scale image)
Visual representation
![Page 19: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/19.jpg)
Reading and opening an image
![Page 20: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/20.jpg)
Selecting a subimage
Just like we can copy a part of an array into another array, we can
copy a part of one image and create a new image.
![Page 21: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/21.jpg)
Changing some pixel values in an image
![Page 22: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/22.jpg)
Saving images in different formats
Image formats:
• jpeg, bmp, png etc.
>> imwrite(I, ‘king.bmp’)
will save I in bmp format.
![Page 23: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/23.jpg)
image rotation
Exercise: Write a one-line statement in Matlab that will rotate an image by 180 degrees.
![Page 24: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/24.jpg)
image rotation
Exercise: Write a one-line statement in Matlab that will rotate an image by 180 degrees.
![Page 25: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/25.jpg)
image rotation
Exercise: Write a one-line statement in Matlab that will rotate an image by 180 degrees.
>> J = I(size(I,1):-1:1, :, :);
![Page 26: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/26.jpg)
Discussions and exercises, Chapter 4
Exercise 4.1
![Page 27: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/27.jpg)
![Page 28: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/28.jpg)
Exercise 4.2
Write statements to do the following operations on a vector x:
1)Return the odd indexed elements.
![Page 29: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/29.jpg)
Exercise 4.2
Write statements to do the following operations on a vector x:
2) Return the first half of x.
![Page 30: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/30.jpg)
Exercise 4.2
Write statements to do the following operations on a vector x:
3) Return the vector in the reverse order.
![Page 31: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/31.jpg)
Exercise 4.3
Given a vector v, and a vector k of indices, write a one or two statement code in Matlab that removes the elements of v in positions specified by k.
Example:>> v = [1, 3, 5, 7, 11, 9, 19]>> k = [2, 4, 5]>> < your code here>>> vans = 1, 5, 9, 19
![Page 32: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/32.jpg)
Exercise 4.3
Given a vector v, and a vector k of indices, write a one or two statement code in Matlab that removes the elements of v in positions specified by k.
![Page 33: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/33.jpg)
Exercise 4.4 what does Matlab output for the following commands?
1) 6 ~= 1 : 10
2) (6 ~= 1) : 10
![Page 34: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/34.jpg)
Exercise 4.4 what does Matlab output for the following commands?
1) 6 ~= 1 : 10
2) (6 ~= 1) : 10
![Page 35: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/35.jpg)
Exercise 4.5. (This is a bit tricky, especially without using a loop construct like while or for.)
Write a statement to return the elements of a vector randomly shuffled.
Hint provided is a useful one.
First understand how sort function works.
![Page 36: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/36.jpg)
Reshaping Arrays
• Arrays are actually stored in column order in Matlab. So internally, a 2 × 3 array is stored as a column vector: A(1,1) A(2,1) A(1,2) A(2,2) A(1,3) A(2,3)
• Any n × m array can be reshaped into any p × q array as long as n*m = p*q using the reshape function.
![Page 37: Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples](https://reader030.vdocuments.mx/reader030/viewer/2022032704/56649d615503460f94a4230f/html5/thumbnails/37.jpg)
Summary
This chapter introduced you to vectors and arrays. For each collection, you saw how to:
■ Create them by concatenation and a variety of special-purpose functions
■ Access and remove elements, rows, or columns
■ Perform mathematical and logical operations on them
■ Apply library functions, including those that summarize whole columns or rows
■ Move arbitrary selected rows and columns from one array to another
■ image – how to create them, open them, change etc.