Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Matrix manupulation to get specific index
1 回表示 (過去 30 日間)
古いコメントを表示
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 件)
Jon
2018 年 4 月 24 日
編集済み: Jon
2018 年 4 月 24 日
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!