《MATLAB从入门到精通》第二章学习小结
学习笔记:
魔方矩阵:幻方(Magic Square)是一种将数字安排在正方形格子中,使每行、列和对角线上的数字和都相等的方法。
Pascal矩阵:由杨辉三角形表组成的矩阵称为帕斯卡(Pascal)矩阵。
注:不加rand('state',0)每次的结果不同,加上每次就是一样的结果。因为这是初始化时刻。
寻址:1.双下标;2.单下标;3.逻辑指标
max(A):返回一个行向量,向量的第i个元素是矩阵A的第i列上的最大值。
[Y,U]=max(A):返回行向量Y和U,Y向量记录A的每列的最大值,U向量记录每列最大值的行号。
mean(A):如果A是一个向量,mean(A)返回A中元素的平均值;如果A是一个矩阵,mean(A)将其中的各列视为向量,把矩阵中的每列看成一个向量,返回一个包含每一列所有元素的平均值的行向量。
median(A):每一列返回一个值,为M该列的从大到小排列的中间值。
矩阵形状信息:
稀疏矩阵:
(省略行号和列号也可以得到相同结果)
sparse Create sparse matrix.
S = sparse(X) converts a sparse or full matrix to sparse form by squeezing
out any zero elements.
S = sparse(i,j,s,m,n,nzmax) uses vectors i, j, and s to generate an
m-by-n sparse matrix such that S(i(k),j(k)) = s(k), with space
allocated for nzmax nonzeros. Vectors i, j, and s are all the same
- Any elements of s that are zero are ignored, along with the
corresponding values of i and j. Any elements of s that have duplicate
values of i and j are added together. The argument s and one of the
arguments i or j may be scalars, in which case the scalars are expanded
so that the first three arguments all have the same length.
S = sparse(i,j,s,m,n) where nzmax = length(s).
S = sparse(i,j,s) where m = max(i) and n = max(j).
S = sparse(m,n) abbreviates sparse([],[],[],m,n,0). This
generates the ultimate sparse matrix, an m-by-n all zero matrix.
For example, this dissects and then reassembles a sparse matrix:
[i,j,s] = find(S);
[m,n] = size(S);
S = sparse(i,j,s,m,n);
So does this, if the last row and column have nonzero entries:
[i,j,s] = find(S);
S = sparse(i,j,s);
All of MATLAB's built-in arithmetic, logical and indexing operations
can be applied to sparse matrices, or to mixtures of sparse and
full matrices. Operations on sparse matrices return sparse matrices
and operations on full matrices return full matrices. In most cases,
operations on mixtures of sparse and full matrices return full
- The exceptions include situations where the result of
a mixed operation is structurally sparse, eg. A .* S is at least
as sparse as S.
See also issparse, spalloc, spones, speye, spconvert, full, find.
cat Concatenate arrays.
cat(DIM,A,B) concatenates the arrays A and B along
the dimension DIM.
cat(2,A,B) is the same as [A,B].
cat(1,A,B) is the same as [A;B].
B = cat(DIM,A1,A2,A3,A4,...) concatenates the input
arrays A1, A2, etc. along the dimension DIM.
When used with comma separated list syntax, cat(DIM,C{:}) or
cat(DIM,C.FIELD) is a convenient way to concatenate a cell or
structure array containing numeric matrices into a single matrix.
Examples:
a = magic(3); b = pascal(3);
c = cat(4,a,b)
produces a 3-by-3-by-1-by-2 result and
s = {a b};
for i=1:length(s),
siz{i} = size(s{i});
end
sizes = cat(1,siz{:})
produces a 2-by-2 array of size vectors.
See also num2cell.
speye Sparse identity matrix.
speye(M,N) and speye([M N]) form an M-by-N sparse
matrix with 1's on the main diagonal. speye(N)
abbreviates speye(N,N).
speye(SIZE(A)) is a space-saving SPARSE(EYE(SIZE(A)))
if A is a 2-D matrix.
bucky Connectivity graph of the Buckminster Fuller geodesic dome.
B = bucky is the 60-by-60 sparse adjacency matrix of the
connectivity graph of the geodesic dome, the soccer ball,
and the carbon-60 molecule.
[B,V] = bucky also returns xyz coordinates of the vertices.
(提供一个足球形状或说是碳60结构的矩阵)
repmat Replicate and tile an array.
B = repmat(A,M,N) or B = repmat(A,[M,N]) creates a large matrix B
consisting of an M-by-N tiling of copies of A. If A is a matrix,
the size of B is [size(A,1)*M, size(A,2)*N].
B = repmat(A,N) creates an N-by-N tiling.
B = repmat(A,P1,P2,...,Pn) or B = repmat(A,[P1,P2,...,Pn]) tiles the array
A to produce an n-dimensional array B composed of copies of A. The size
of B is [size(A,1)*P1, size(A,2)*P2, ..., size(A,n)*Pn].
If A is m-dimensional with m > n, an m-dimensional array B is returned.
In this case, the size of B is [size(A,1)*P1, size(A,2)*P2, ...,
size(A,n)*Pn, size(A, n+1), ..., size(A, m)].
repmat(A,M,N) when A is a scalar is commonly used to produce an M-by-N
matrix filled with A's value and having A's CLASS. For certain values,
you may achieve the same results using other functions. Namely,
repmat(NAN,M,N) is the same as NAN(M,N)
repmat(SINGLE(INF),M,N) is the same as INF(M,N,'single')
repmat(INT8(0),M,N) is the same as ZEROS(M,N,'int8')
repmat(UINT32(1),M,N) is the same as ONES(M,N,'uint32')
repmat(EPS,M,N) is the same as EPS(ONES(M,N))
Example:
repmat(magic(2), 2, 3)
repmat(uint8(5), 2, 3)
Class support for input A:
float: double, single
integer: uint8, int8, uint16, int16, uint32, int32, uint64, int64
char, logical
See also bsxfun, meshgrid, ones, zeros, nan, inf.
(repmat (A, [m n]):实际上是形成m行n列的矩阵,其中元素都是以A作为拷贝)
多项式:
学习心得:
矩阵真的把我摁在地上摩擦...
这章非常的杂(乱)