Sparse Matrices
When a matrix has a large number of Os, it is advantageous to express it in sparse form to reduce storage requirements. Function sparse converts a matrix to sparse form by “squeezing out” all zero elements. The basic syntax for this function is :
Z1 = sparse(Z)
Example
>> Z = [1 0 3; 0 5 6; 0 9 0] Z = 1 0 3 0 5 6 0 9 0 >> Z1 = sparse(Z) Z1 = (1,1) 1 (2,2) 5 (3,2) 9 (1,3) 3 (2,3) 6