Tuesday, January 22, 2008

Matlab

Some issues in the course of using Matlab:
(1) random number generation
    functions:
        rand:
            generate random numbers in range [0, 1];
        randn:
             Random numbers are drawn from a normal distribution with mean zero and standard deviation one. So generated numbers may be negative.

Usage hints:
    In description above, those functions ouput decimal numbers. If you want to generate integers in range, following usage may be useful:
    output = ceil(max.*rand(n1, n2, ...ni))
    output = min + ceil((max-min).*rand(n1,n2,...ni))

Some key points from Matlab help:
   The sequence of numbers produced by RAND is determined by the internal state of the generator. Setting the generator to the same fixed state allows computations to be repeated.  Setting the generator to different states leads to unique computations, however, it does not improve any statistical properties. Since MATLAB resets the state at start-up, RAND will generate the same sequence of numbers in each session unless the state is changed.
So, it is a better to set the initial state of random number generator before random numbers are generated. This can be done in following format:
    rand('state', sum(100*clock));

More random number generation functions which use specific statistic models:
betarnd 贝塔分布的随机数生成器
binornd 二项分布的随机数生成器
chi2rnd 卡方分布的随机数生成器
exprnd 指数分布的随机数生成器
frnd f分布的随机数生成器
gamrnd 伽玛分布的随机数生成器
geornd 几何分布的随机数生成器
hygernd 超几何分布的随机数生成器
lognrnd 对数正态分布的随机数生成器
nbinrnd 负二项分布的随机数生成器
ncfrnd 非中心f分布的随机数生成器
nctrnd 非中心t分布的随机数生成器
ncx2rnd 非中心卡方分布的随机数生成器
normrnd 正态(高斯)分布的随机数生成器
poissrnd 泊松分布的随机数生成器
raylrnd 瑞利分布的随机数生成器
trnd 学生氏t分布的随机数生成器
unidrnd 离散均匀分布的随机数生成器
unifrnd 连续均匀分布的随机数生成器
weibrnd 威布尔分布的随机数生成器
(2)permutation
This topic is related to how to generate permutations.
functions:
   (1) randperm(n)
        a random permutation of the integers 1:n.
(3) Dimension rearrangement
functions:
    (1) permute(A, dim_order)
        This function is useful when you want to adjust order of different dimensions.
    (2) ipermute(A, dim_order)
        Inverse permute the dimensions of an array.
        If B = ipermute(A, dim_order) then A=permute(B,dim_order).
(4) Matrix metadata retrieval
functions:
    (1) ndims
        Number of array dimensions. It is equal to length(size(array)).
    (2) size
(5) Matrix data retrieval
functions:
    (1) find
    (2) nonzeros
    (3) min
    (4) max
(6) Array index conversion
    (1) sub2ind
    (2) ind2sub
(7) Array generation
    (1) zeros
    (2) ones
    (3) linspace
    (4) logspace
(8) Array transformation
    (1) reshapce
    (2) shiftdim
    (3) circshift
    (4) squeeze
    (5) repmat
(9) Bitwise operations
    (1) bitshift
(10) Image related
    (1) imread, imwrite
(11) color related
    (1) rgb2gray, rgb2hsv, rgb2ind, rgb2ntsc, rgb2ycbcr