%sparsity has to be between 0 to 1.įor making a sparse column vector, set M=1 & for sparse row vector, set N=1. Well its very simple, MATLAB have some inbuilt functions to achieve this task! (Yes there are many other & efficient ways to generate rather using this inbuilt commands that we will discuss in our upcoming articles.)įunction 1: speye(N) -> This command will create a sparse NxN identity matrix & store it as a sparse data type.įunction 2: sprand(M,N,% sparsity) -> This command will generate a sparse MxN random sparse matrix whose element's value varies from 0 to 1 & store it as a sparse data type. So, after understanding all these stuffs, the question will be How to generate A sparse Matrix or Vector in MATLAB? Similarly it is applicable to Matrix operations like subtraction (if dimensions are agreed), multiplication(if dimensions are agreed), transpose, inverse(if non singular).