Borrar filtros
Borrar filtros

Extract two closest rows of a matrix

1 visualización (últimos 30 días)
amir
amir el 20 de Mzo. de 2016
Comentada: amir el 21 de Mzo. de 2016
Hello,
How can I extract two closest rows of a matrix and set one of them to zero?
thank you.
  3 comentarios
Image Analyst
Image Analyst el 20 de Mzo. de 2016
Well, here is the "set to zero" part
yourMatrix(closestRow, :) = 0;
to determine what scalar value you need for closestRow, you need to answer dpb's question.
amir
amir el 20 de Mzo. de 2016
I have two different matrixes of [x y width height] which the size of each matrix might vary in size over the time. I have merged them together and got one matrix as the result. Now I am planning to check for the two closest [x y] coordinates within this matrix and eliminate one.
In the following example, the first two rows of result matrix are closest to each other in [x y]. Then, either first row or second row need to be removed/or set to zero.
Matrix A =
385 208 108 108
matrix B =
398 223 96 96
113 225 114 114
Result Matrix=
385 208 108 108
398 223 96 96
113 225 114 114

Iniciar sesión para comentar.

Respuesta aceptada

dpb
dpb el 21 de Mzo. de 2016
d=pdist(M(:,2)); % find the pairwise differences
ix=find(min(d(1:end-1)); % shortest distance excluding wraparound of 3-1
M(ix,:)=[]; % remove that row

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by