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!