Info
This question is closed. Reopen it to edit or answer.
Matrix manupulation to get specific index
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Jon
on 24 Apr 2018
Edited: Jon
on 24 Apr 2018
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 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!