Search Contact information
University of Cambridge Home Department of Engineering
University of Cambridge >  Engineering Department >  computing help
next up previous contents
Next: File Input/Output Up: Using Matlab at CUED Previous: Creating User Interfaces

Sparse Arrays

If you know that your matrices will stay nearly empty, then make them sparse.
% comparison of sparse vs full matrices
% Create sparse and full versions of the same matrix.
% Note that the density is 0.05. The break-even point
% for this operation seems to be about 0.25.
S = sprandn(60,60,0.05);
F = full(S);
% Compare speed.
disp('Sparse')
t0=cputime;
B = S * S;
cputime-t0
disp('Full')
t0=cputime;
C = F * F;
cputime-t0



© Cambridge University Engineering Dept
Information provided by Tim Love
2006-07-24