difference matrix??

1 visualización (últimos 30 días)
Walter
Walter el 24 de Abr. de 2012
I'm not sure what this is called, but I want to calculate the cross-differences?? of values in a matrix such that:
f(
1 5 8
3 6 7
4 5 2
6 8 1
)
produces:
[
0 4 7
-4 0 3
-7 -3 0
]
[
0 3 4
-3 0 1
-4 -1 0
]
[
0 1 -2
-1 0 3
2 -3 0
]
[
0 2 -5
-2 0 -7
5 7 0
]
does anyone know what this is called, and how I can do it?

Respuesta aceptada

Sean de Wolski
Sean de Wolski el 24 de Abr. de 2012
x = [1 5 8
3 6 7
4 5 2
6 8 1]';
sz = size(x);
C = bsxfun(@minus,reshape(x,1,sz(1),sz(2)),reshape(x,sz(1),1,sz(2)))
  2 comentarios
Walter
Walter el 24 de Abr. de 2012
awesome.. do you know what this is called?
Sean de Wolski
Sean de Wolski el 24 de Abr. de 2012
Nope. But I do know that it is very bsxfun-friendly and that makes it cool.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by