Find indices of the lowest neighbour in matrix
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Morten Jørgensen
el 29 de En. de 2020
Respondida: Vinai Datta Thatiparthi
el 3 de Feb. de 2020
I'm trying to find the indices of the lowest value of three neighbours (red in picture below) for backtracking a path in a matrix
i = 331
j = end
[x y] = min([cost(end-1,j-1) cost(end,j-1) cost(end-1,j)])
Can anyone help me with this?
thanks
0 comentarios
Respuestas (1)
Vinai Datta Thatiparthi
el 3 de Feb. de 2020
Hello Morten,
matVal = [ .. ]; % Enter your input matrix here
% Enter the coordinates for the value of which you want to find the least neighbour of
xCoOrd = .. ;
yCoOrd = .. ;
% Find out all the neighbours of the element that you picked
convOut = conv2(double(I==I(xCoOrd, yCoOrd)), ones(3,3), 'same');
idx = find(convOut - double(I==I(xCoOrd, yCoOrd)));
% The index of the least neighbour
leastNeighbourIdx = find(I == min(I(idx)));
Hope this helps!
0 comentarios
Ver también
Categorías
Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!