finding column # that contains an integer in a matrix

12 Ansichten (letzte 30 Tage)
mehrdad asadi
mehrdad asadi am 7 Jul. 2015
Kommentiert: mehrdad asadi am 7 Jul. 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

Akzeptierte Antwort

James Tursa
James Tursa am 7 Jul. 2015
Bearbeitet: James Tursa am 7 Jul. 2015
X = your matrix;
indices = find(any(X==5)); % columns that have the number 5 in them
  4 Kommentare
James Tursa
James Tursa am 7 Jul. 2015
indices = find(any(X==5,2)); % rows that have the number 5 in them

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by