Matrix manupulation to get specific index
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
I have a matrix like this.
1 1 1
1 9 1
0 1 0
With my central value being 9 and i would like to find all the values which are 0 and thier location that surrounds my central value.
In that way i have my results being (3, 1) and (3, 3)
Is there a function that can do this?
댓글 수: 0
답변 (1개)
You can use the MATLAB find function for this. For example:
% Define your matrix
A = [1 1 1;1 9 1;0 1 0];
% use find function with two return arguments giving row and column indices where match occurs
[rIdx,cIdx] = find(A == 0);
% display the results by putting them into a matrix where each row gives the row and column indices
% in the original matrix where the elements have a value of zero
result = [rIdx cIdx];
disp(result)
댓글 수: 0
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!