Find indices of the lowest neighbour in matrix
조회 수: 1 (최근 30일)
이전 댓글 표시
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)])
![Screenshot 2020-01-29 at 11.48.50.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/268940/Screenshot%202020-01-29%20at%2011.48.50.png)
Can anyone help me with this?
thanks
댓글 수: 0
답변 (1개)
Vinai Datta Thatiparthi
2020년 2월 3일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!