# Use Of ‘sparse()’ Command In MatLab(Illustrated Expression)

If you need to deal with matrices has lots of ’0’ values in their elements, you can use ‘sparse()’ code in Matlab to define and illustrate them. In this article we will show you how to use ‘sparse()’ command in Matlab to define and illustrate matrices that has lots of ‘zeros’ inside them as elements.

### How To Use ‘sparse()’ Command In Matlab?

For example, there is a matrix such as ‘a’ as shown by red arrow that includes lots of zeros inside it. And the elements that are non-zero integers are in minority or ‘sparse’ in that matrix. We can show these kinds of matrices in the form of ‘b’ as shown by second green arrow above by typing sparse(a) code as shown by green arrow again.

Also you can create matrices directly from sparse() command in Matlab. As we stated above the use of sparse() command is very helpful for matrices that includes zeros in the majority of their elements. So you can only define the minority of non-zero integers inside these matrices, and the places of them.

For example, we created three of vectors inside green box above that the first one includes the row numbers of minority non-zero integers, the second one include the column number of minority non-zero integers. And the values of these minority integers are given at the third vector. What you need to do is, define these vectors respectively inside the parantheses of sparse() command as shown by blue arrow above. And you need to add the dimensions of matrix such as 4, 4 which is 4×4 matrix.

The illustration of these sparse matrices in command window is as shown by blue and green arrows. First column of binary numbers are showing the places of these non-zero numbers inside the matrix, and the second column of integers are the minority non-zero numbers inside the matrix.

The use of sparse() command in Matlab is very simple like above. Leave your comments and questions about ‘sparse()’ command in Matlab below!