Knowing your Matrices

  • In certain computational assignments, you may have to deal with very big matrices (e.g. 100-by-100) and in such cases you might be unsure of the dimensions of the matrix you’re working with. The following commands will enable you to know more about any matrix you have any doubts about. Using the 6-by-6 matrix, J as an example:

a

Command Function
 size States the size of the matrix.2
length States length of largest matrix dimension e.g. would be 5 for a row matrix with 5 elements. 

3

numel States the number of elements. 

 

4

iscolumn Checks if matrix is a column matrix. Outputs 1 if it is and 0 if it is not. 

5

isrow Checks if matrix is a row matrix. Outputs 1 if it is and 0 if it is not. 

6

min and max Outputs a row matrix with smallest or largest elements in each column. 

7

EXERCISE 2

For a column matrix, D with ten elements what would be the result of the following commands? (Unsure? Try constructing such a matrix and running the code.)

(a)  size(D) (b)  length(D)    (c)  numel(D)   (d)  isrow(D)    (e)  iscolumn(D)

MISCELLANEOUS EXERCISE

Declare a new parameter K whose only element is 1. Is this a matrix? Is it a vector or a scalar? Try to answer these questions for yourself before you proceed.

Check your answers using the following commands ismatrix, isscalar and isvector. Surprised? Now declare a new variable, T by configuring it to be the longest dimension of matrix J above (i.e. use the length command). Repeat the exercise for this new parameter.

[Show]


(For more on Matrix commands follow the link: Advanced Matrix Commands)