Wednesday 2 October 2013

Using Matlab Functions

    • See list in book, or below, or follow the link to the full online list of Matlab functions
    • Check help ( or helpwin ) on elmat, elfun, specfun, randfun
    • Use "lookfor" to search for functions
    • Click on the "Fx" function icon on the left edge of the Matlab command window, if available.
    • Matlab trig functions sin, cos, tan assume angles in radians, just like C++
      • sind, cosd, tand assume angles in degrees
    • Some functions return multiple results
      • A = [ 1, 2, 3; 4, 5, 6 ]
      • size( A ) % returns [ 2, 3 ]
      • [ nrows, ncols ] = size( A ); % stores results in nrows and ncols
    • Some functions' results vary with dimension of input:
      • max( 1-D vector ) returns a single maximum value.
      • [ value, position ] = max( 1-D vector ) returns the maximum and its position
      • max( 2-D matrix ) returns a row vector containing the max of each column
        • max( max( 2-D matrix ) ) returns the maximum value in the matrix.
          • ( As does max( 2-D_matrix( : ) ) )
    • Common Matlab Functions. Note that many of the aggregating functions ( e.g. max, min, mean ) return a row vector of the operation applied on each column separately when applied to a matrix. A few functions worth noting:
      • ( See the Function Browser in Matlab help for a more complete list, or read the help documentation on a particular subject such as linear algebra. )
      • abs
      • acos
      • acosh
      • asin
      • asinh
      • atan
      • atan2( y, x ) - Arctangent of y / x, between -pi and pi.
      • atanh
      • ceil - smallest integer that exceeds its argument. ceil( 3.1 ) is 4, ceil( -3.9 ) is -3.
      • clock - time and date in a six-element vector.
      • cos
      • cosh
      • cot
      • csc
      • cumsum - cumulative sum, i.e. cumsum( [ 1 2 3 4 ] ) yields [ 1 3 6 10 ].
      • date
      • exp - exponential, base e.
      • fix - nearest integer towards zero. fix( 3.9 ) is 3, fix( -3.9 ) is -3.
      • fix - nearest integer towards zero. fix( 3.9 ) is 3, fix( -3.9 ) is -3.
      • floor - largest integer not exceeding its argument - floor( 3.9 ) is 3, floor( -3.1 ) is -4.
      • length - number of elements in a vector, or number of columns in a matrix.
      • log - natural logarithm
      • log10 - base 10 logarithm.
      • max - Maximum. When applied to a matrix, yields a vector with the maximums of each column.
      • mean - Average. See max.
      • min - Minimum. See max.
      • mod( X, Y ) - returns X - n.*Y where n = floor(X./Y). Like mod in C, but works with all types of numbers.
      • pow2 - Two raised to the power of the argument.
      • prod - product of the elements of its argument. prod( [ 2 3 5 ] ) is 30.
      • rand - generates pseudo-random numbers in the range of [ 0, 1 ).
        • Initialize the random number generator ONCE with rand( 'state', sum( 100*clock))
      • realmax - largest positive floating point number ( for this installation on this computer. )
      • realmin - smallest positive floating point number ( same ).
      • rem( x, y ) - remainder when x is divided by y.
        • Strictly speaking, returns x - ( y * fix( x / y ) ), which defines actions for negative and non-integer operands.
      • round - rounds off to nearest integer. round( 3.5 ) = 4, round( -3.5 ) = -4.
      • size - Returns all dimensions of its argument, e.g. number of rows and number of columns for a 2-D matrix.

No comments:

Post a Comment