finding column # that contains an integer in a matrix

3 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

James Tursa
James Tursa il 7 Lug 2015
Modificato: James Tursa il 7 Lug 2015
X = your matrix;
indices = find(any(X==5)); % columns that have the number 5 in them
  4 Commenti
James Tursa
James Tursa il 7 Lug 2015
indices = find(any(X==5,2)); % rows that have the number 5 in them

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by