Effacer les filtres
Effacer les filtres

finding column # that contains an integer in a matrix

5 vues (au cours des 30 derniers jours)
mehrdad asadi
mehrdad asadi le 7 Juil 2015
Commenté : mehrdad asadi le 7 Juil 2015
hi,
I want to find indices of columns of a matrix which contains a specific integer.
say magic(5), how can I find column numbers that has got '5' in it if it exists!
thanks,
Mehrdad

Réponse acceptée

James Tursa
James Tursa le 7 Juil 2015
Modifié(e) : James Tursa le 7 Juil 2015
X = your matrix;
indices = find(any(X==5)); % columns that have the number 5 in them
  4 commentaires
James Tursa
James Tursa le 7 Juil 2015
indices = find(any(X==5,2)); % rows that have the number 5 in them
mehrdad asadi
mehrdad asadi le 7 Juil 2015
got it!
thanks

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by