'closeness' of multiple vectors

Is there a way to compute how 'closely' a data vector matches another? For example:
A = [1 2 3 4 5];
B = [1 2 3 4 5];
C = [6 7 8 9 10];
Can I use vector A to compare the closeness against vector B, and then vector C? For (A,B), the closeness should be 100%, where as for (A,C) it should be 0%...

 Respuesta aceptada

Richard Brown
Richard Brown el 22 de Abr. de 2012

0 votos

Is closeness a measure of how many entries match in matching positions? In this case:
closeness = @(x, y) nnz(x == y) / numel(x);
A = [1 2 3 4 5];
B = [1 2 3 4 5];
C = [6 7 8 9 10];
closeness(A, B)
closeness(A ,C)
If your vectors can have noninteger entries, then to mitigate against floating point errors you'd replace x == y with abs(x - y) < tol * abs(x) where tol is something small, like 1e-14.

3 comentarios

Walter Roberson
Walter Roberson el 22 de Abr. de 2012
closeness = @(x,y) mean(x(:)==y(:));
Richard Brown
Richard Brown el 23 de Abr. de 2012
haha, yes that's better :)
Philip
Philip el 23 de Abr. de 2012
That's perfect! Thanks to you both for your quick answers!!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Preguntada:

el 22 de Abr. de 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by