Learn R Programming

RnavGraphImageData (version 0.0.4)

L2Distance: Euclidean distances between vector in A and B

Description

This fully vectorized (VERY FAST!) m-file computes the Euclidean distance between two vectors by:

||A-B|| = sqrt ( ||A||^2 + ||B||^2 - 2*A.B )

Usage

L2Distance(a, b, df = 0)

Arguments

a

Either a matrix or a vector.

b

Either a matrix or a vector.

df

df = 1, force diagonals to be zero; 0 (default), do not force.

Value

For A - (DxM) matrix B - (DxN) matrix

L2Distance returns a matrix of size (MxN).

Examples

Run this code
# NOT RUN {
A = matrix(runif(400*100),ncol=100)
B = matrix(runif(400*200),ncol=200)

d = L2Distance(A,B)
# }

Run the code above in your browser using DataLab