Scientific Computing & Visualization
Help Contact
About Accounts Computation Visualization Documentation Services

Introduction to MATLAB

Defining matrices via the vector technique

Using the for loop in MATLAB is relatively expensive. It is much more efficient to perform the same task using the vector method. For example, the following task

for j=1:n     
   for i=1:m          
     A(i,j) = B(i,j) + C(i,j);      
   end     
end  
can be more compactly and efficiently represented (and computed) by the vector method as follows:
A(1:m,1:n) = B(1:m,1:n) + C(1:m,1:n);  
If the matrices are all of the same size (as is the case here), then the above can be more succinctly written as
A = B + C;  
For sufficiently large matrix operations, this latter method is vastly superior in performance. More examples ...

unk unk unk
Documentation
Boston University
Boston University
 
OIT | CCS | July 7, 2009  
Scientific Computing & Visualization Boston University home page Boston University home page