Text-only Table of Contents (frame/ no frame)
(12) Vectorization Previous Top Next

Performance Increase - Vectorization



Example Using Loops (what you do in most programming languages)
m=rand(5,1000); l=rand(5,1000);
w=rand(5,1000); h=rand(5,1000);
[rows,cols] =size(m);
for i= 1:rows
    for j=1:cols
        density(i,j)=m(i,j)/(l(i,j)*w(i,j)*h(i,j));
    end
end


Example Using Array Operations
m=rand(5,1000); l=rand(5,1000);
w=rand(5,1000); h=rand(5,1000);
density=m./(l.*w.*h);


Example: array_vs_loops




Previous Top Next


Vectorization.src  last modified Oct 17, 2007 Introduction Table of Contents
(frame/no frame)
Printable
(single file)
© Dartmouth College