Things under legendu
Unlike most other programming languages, to get elements of an array in MATLAB, you have to parentheses to specify index. If you want to get or set elements of a cell in MATLAB, you have to use curly braces. If you use parentheses to extract elements of a cell, the result will still be a cell.
vrrotmat2vecconverts a rotation matrix to its axis-angle representation. Conversely,vrrotvec2matconverts an axis-angle (the axis do not have to be a unit one, as long as it is not a zero vector) representation of a rotation matrix to a matrix form. There are also many other representations of a rotation matrix, e.g. Euler angle representation and quaternion representation.dcm2angleandangle2dcmconverts between a rotation matrix and its Euler angle representation;quat2dcmanddcm2quatconverts between a rotation matrix and its quaternion representation;quat2angleandangle2quatconverts between the Euler angle representation and quaternion representation of a rotation matrix.You can use
allto check whether the elements of a vector (either a column vector or a row vector) are alltrue(or non-zero values). How ever if you applyallon an matrix or a multi-dimensional array, you will get vectors or arrays of boolean values depending on the dimension you specified. To check whether all elements of a matrix or multi-dimensional array aretrue(or non-zero values), you have useallmore than once. For example, ifbmatis a boolean matrix in MATLAB, you can useall(all(bmat))to check whether all elements ofbmataretrue.anyworks similarly toall.You can use
sizeto get the dimensions of an array. You can specify more output variables than necessary forsize, and these redundant variables will have value1. If you specify less output variables than the dimension of the array, then the last output variable is the product of these left dimensions. To get the dimension of an arraya, you can simply usesize(a,k). If you are just interested in the first two dimensions of a multi-dimensional arraya, then you can use to extract the first two dimensions, where means that the left dimensions will be ignored.To get the largest dimension of an array, you can use
length, which is different from R that useslengthto get the total number of elements in an array or list. To get the total number of elements of an array in MATLAB, you have to usenumel.arrayfunapplies a given function to each element of an array, which is similar toapplyin R.arrayfunin MATLAB is not as convenient asapplyin R which can also apply a function to marginals of an arrays instead of only elements of the array, however there are some functions (mostly statistical summary functions) in MATLAB that allows you to work on specified marginals of an array, e.g.size,max,meanand so on. Use these functions can avoid inconvenient loops in MATLAB. Sometimes, you might want to pass extra parameters to the function that is to be applied to each element of an array. <To do this, please refer to ...> Similar toarrayfun,cellfunapplies a given function to each element in a cell array. From my experience,cellfunhas advantage when its elements have different sizes (or even types), which make coding simpler. It does not seem to speed up the code compared to loops. There is also anotherspfunwhich applies a given function to non-zero elements of a sparse matrix.In
Ra vectors is very flexible, and it can be a row vector or a column vector depends on different situations. A vector in R is different from a matrix. In MATLAB a vector is a matrix (either 1\times n\)' or n\times1)') and thus there are both column vectors and row vectors in MATLAB. Function and operations usually behave differently on row vector and column vector in MATLAB. Since a vector in MATLAB is essentially a matrix, operations on vectors must be compatible matrix operations. Since in Mathematics vectors are column vectors by default, you’d better use column vectors in MATLAB if both row and column vectors are OK.You can use
isemptyto check whether an array is empty in MATLAB,nullcalculates the null space of a matrix.repmatreplicates and tile array.eigsis frequently used to find the eigenvalues of sparse square matrices. Because a sparse square matrix usually has a very large dimension, it has a large amount (the same as its dimension) of eigenvalues. Usually only a few of them are interesting. To calculate the $k)’ large eigenvalue of a sparse matrixspm, you can useeigs(spm,k).