
253Implicit Parallelization (Vectorization and Indexing)
0.5
4
2
0
–2
–4
–2
–1
0
1
0
vectorized usage example
Additional examples of using meshgrid can be found in the references.
794
meshgrid can
create 2D and 3D matrices; for higher dimensions, we can use ndgrid.
5.3.8 Euclidean Distances
Given two sets A,B of coordinates (x,y,z), let’s nd the Euclidean distance r from each point
in A to each point in B:
795
% Common problem definition/initialization
A = rand(1000,3); % 1000 points
B = rand(3000,3); % 3000 points
sizeA = size(A,1); % # of points (rows) in A = 1000
sizeB = size(B,1); % # of points (rows) in B = 3000
% Slow, standard version ...