%% Convert Sparse Matrix to Full Storage
% Change the storage format of a matrix and compare the storage requirements.
% Create a random sparse matrix. The display of sparse matrices in MATLAB ® omits all zeros and shows the location and value of nonzero elements.

rng default %for reproducibility
S = sprand(8,8,0.3)

%
% Convert the matrix to full storage. The MATLAB display of the matrix reflects the new storage format.

A = full(S)

%
% Compare the storage requirements of the two formats:
% A uses storage for 64 doubles (8 bytes each), or 64\cdot 8=512 bytes.
% S uses storage for 15 nonzero elements, as well as 24 integers describing their positions, for a total of 39\cdot 8=312 bytes.

whos

%
% Copyright 2018 The MathWorks, Inc.