%% Preallocate Storage in Sparse Matrix
% Create a sparse matrix with 10 nonzero values, but which has space allocated for 100 nonzero values.

S = sparse(1:10,1:10,5,20,20,100);
N = nnz(S)

%

N_alloc = nzmax(S)

% The spalloc function is a shorthand way to create a sparse matrix with no nonzero elements but which has space allotted for some number of nonzeros.
% Copyright 2015 The MathWorks, Inc.