失效链接处理 |
Digital Image Processing Using Matlab - Gonzalez Woods & Eddins (Better Version) PDF 下载
本站整理下载:
相关截图:
![]()
主要内容:
Entering Matrices
The best way for you to get started with MATLAB is to learn how to handle
matrices. Start MATLAB and follow along with each example.
You can enter matrices into MATLAB in several different ways:
• Enter an explicit list of elements.
• Load matrices from external data files.
• Generate matrices using built-in functions.
• Create matrices with your own functions in M-files.
Start by entering Dürer’s matrix as a list of its elements. You only have to
follow a few basic conventions:
• Separate the elements of a row with blanks or commas.
• Use a semicolon, ; , to indicate the end of each row.
• Surround the entire list of elements with square brackets, [ ] .
To enter Dürer’s matrix, simply type in the Command Window
A = [16 3 2 13; 5 10 11 8; 9 6 7 12; 4 15 14 1]
2-4
Matrices and Magic Squares
MATLAB displays the matrix you just entered:
A =
16 3 2 13
5 10 11 8
9 6 7 12
4 15 14 1
This matrix matches the numbers in the engraving. Once you have entered
the matrix, it is automatically remembered in the MATLAB workspace. You
can refer to it simply as A . Now that you have A in the workspace, take a look
at what makes it so interesting. Why is it magic?
sum, transpose, and diag
You are probably already aware that the special properties of a magic square
have to do with the various ways of summing its elements. If you take the
sum along any row or column, or along either of the two main diagonals,
you will always get the same number. Let us verify that using MATLAB.
The first statement to try is
sum(A)
MATLAB replies with
ans =
34 34 34 34
When you do not specify an output variable, MATLAB uses the variable ans ,
short for answer, to store the results of a calculation. You have computed a
row vector containing the sums of the columns of A . Each of the columns has
the same sum, the magic sum, 34.
How about the row sums? MATLAB has a preference for working with the
columns of a matrix, so one way to get the row sums is to transpose the
matrix, compute the column sums of the transpose, and then transpose the
result. For an additional way that avoids the double transpose use the
dimension argument for the sum function.
MATLAB has two transpose operators. The apostrophe operator (e.g., A' )
performs a complex conjugate transposition. It flips a matrix about its main
|