Matlab基本命令

ones
Create array of all ones
Y = ones(n)
Y = ones(m,n)
Y = ones([m n])
Y = ones(m,n,p,...)
Y = ones([m n p ...])

Y = ones(n) returns an n-by-n matrix of 1s. An error message appears if n is not a scalar.
Y = ones(m,n) or Y = ones([m n]) returns an m-by-n matrix of ones.
Y = ones(m,n,p,...) or Y = ones([m n p ...]) returns an m-by-n-by-p-by-... array of 1s.

 

 

sum
Sum of array elements

B = sum(A)
B = sum(A,dim)
B = sum(..., 'double')
B = sum(..., dim,'double')
B = sum(..., 'native')
B = sum(..., dim,'native')
Description

B = sum(A) returns sums along different dimensions of an array.

If A is a vector, sum(A) returns the sum of the elements.

If A is a matrix, sum(A) treats the columns of A as vectors, returning a row vector of the sums of each column.

If A is a multidimensional array, sum(A) treats the values along the first non-singleton dimension as vectors, returning an array of row vectors.
 

 

size

Array dimensions

d = size(X)
[m,n] = size(X)
m = size(X,dim)
[d1,d2,d3,...,dn] = size(X),
Description

d = size(X) returns the sizes of each dimension of array X in a vector d with ndims(X) elements. If X is a scalar, which MATLAB regards as a 1-by-1 array, size(X) returns the vector [1 1].

[m,n] = size(X) returns the size of matrix X in separate variables m and n.

m = size(X,dim) returns the size of the dimension of X specified by scalar dim.

 

 

randn

Normally distributed random numbers

Y = randn
Y = randn(n)
Y = randn(m,n)
Y = randn([m n])
Y = randn(m,n,p,...)
Y = randn([m n p...])
Y = randn(size(A))
randn(method,s)
s = randn(method)
Description

Y = randn returns a pseudorandom, scalar value drawn from a normal distribution with mean 0 and standard deviation 1.

Y = randn(n) returns an n-by-n matrix of values derived as described above.
Y = randn(m,n) or Y = randn([m n]) returns an m-by-n matrix of the same.
Y = randn(m,n,p,...) or Y = randn([m n p...]) generates an m-by-n-by-p-by-... array of the same.
 

 

 生成特殊矩阵

产生10*10的全0矩阵: zeros(10,10) 
产生10*10的全1矩阵: ones(10,10)
产生10*10的单位矩阵: eye(10,10)
产生10*10的0~1间均匀分布的随机矩阵。 rand(10,10)
产生10*10的均值为0,方差为1的标准正态分布随机矩阵: randn(10,10)

 

posted @ 2011-03-25 21:35  Keosu  阅读(668)  评论(0编辑  收藏  举报