How to find dimension of vectors and matrices in Matlab | applied electronics engineering

Latest

How to find dimension of vectors and matrices in Matlab

By Applied Electronics - Friday, February 24, 2017 No Comments
Matlab is a very good programming software when it comes to vector and matrices. Often you need to determine your vector or matrix dimension such as length and size. There are few inbuilt functions that you can use to determine the length and size of vector and matrices.

This is continuing tutorial on vector and matrices in Matlab. In the last tutorials we showed you how to create vectors and matrices in Matlab and how to refer and modify matrix elements in Matlab

How to find dimension of a vector in Matlab


Consider a vector first. To find length of a vector you can use the length() function and to find the size you can use the size() function.Consider a vector vec which has elements from -2 to 1, that is, -2, -1, 0 and 1. This vector has thus 4 elements and since it is a row vector it size is 1x4 which means one row and 4 columns. The following illustrates how to find length and size of the vector vec.



How to find dimension of a matrix in Matlab


Now consider how to find dimension, that is length and size of a matrix in Matlab. For this lets make a matrix mat as follows.


Now what is the length of this matrix? what do you think matlab will return if we try to find its length using the length() function? When length is used in matrix in matlab then matlab will return either the row or column whichever is larger. In this case the row is 3 and column is 2 so Matlab will return number of row 3,

Similarly we can get the size of the matrix using the size() function as follows,


So in this way you can find dimension of vectors and matrices in Matlab.



No Comment to " How to find dimension of vectors and matrices in Matlab "