
140 Accelerating MATLAB
®
Performance
than true-color RGB images (e.g., PNG) for at-color cartoons.* However, while no space
is allocated for unused indexes, space is indeed allocated for all possible column indexes
as a global overhead. For this reason, it is generally better to reshape the data such that
the large dimension is stored as the sparse-data row rather than the column (i.e., ensure a
smaller column dimension):
360
s1 = sparse([],[],[],1,N); % row vector - slower, more memory
⇨ Elapsed time is 0.023915 seconds.
s2 = sparse([],[],[],N,1); % column vector - much faster, low memory
⇨ Elapsed time is 0.000031 seconds.
>> whos s1 s2 ...