| MatArray Toolbox | Search  Help Desk |
| dl2cNaN | Examples See Also |
dl2cNaN is a mex-file that calculates the
euclidian distance between the columns
of a matrix or between the columns of two matrices. The
NaN values are discarded for the distance
calculation. The distances are divided by the number of
non-NaN values.
Syntax
d = dl2cNaN(a) d = dl2cNaN(a,[]) d = dl2cNaN(a,b)
Description
dl2cNaN is a fast mex-file implementation of
the euclidian distances between columns. It is useful for the quick
calculation of distances in K-means or hierarchical clustering.
It is similar to dl2c, except that missing values
are discarded and that the distances are divided by the number
of non-NaN values. The square root however is not taken.
dl2cNaN is about 4 times slowlier than dl2c,
so use only if needed.
The first version of the call returns a symmetrical
square matrix d whose values are the squared distances
between the columns
of the matrix a (e.g. d(2,5) is the
squared distance between the second and the fifth column of
the matrix a, that is
nanmean( (a(:,2)-a(:,5)).^2 )).
The second version returns a linear matrix of distances, in
a fashion similar to pdist in the statistic toolbox.
The advantage is that no redundant information is stored, hence
a gain in space of a factor of about 2. It is possible to obtain
the square form with a call to squareform. See the
statistic toolbox for more information.
The third version returns the distances between the columns
of the matrices a and b. The element
d(i,j) is the distance between the vectors
a(:,j) and b(:,i)
Examples
» X = magic(3);
» X([1 6]) = [NaN NaN]
X =
NaN 1 6
3 5 7
4 NaN 2
» dl2c(X)
ans =
0 NaN NaN
NaN 0 NaN
NaN NaN 0
» dl2cNaN(X)
ans =
0 4.0000 10.0000
4.0000 0 14.5000
10.0000 14.5000 0
See Also
dl2c,
nanmean,
pdist,
squareform