Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Matrix manupulation to get specific index
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Jon
le 24 Avr 2018
Modifié(e) : Jon
le 24 Avr 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 commentaires
Cette question est clôturée.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!