Borrar filtros
Borrar filtros

finding column # that contains an integer in a matrix

2 visualizaciones (últimos 30 días)
mehrdad asadi
mehrdad asadi el 7 de Jul. de 2015
Comentada: mehrdad asadi el 7 de Jul. de 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

Respuesta aceptada

James Tursa
James Tursa el 7 de Jul. de 2015
Editada: James Tursa el 7 de Jul. de 2015
X = your matrix;
indices = find(any(X==5)); % columns that have the number 5 in them
  4 comentarios
James Tursa
James Tursa el 7 de Jul. de 2015
indices = find(any(X==5,2)); % rows that have the number 5 in them
mehrdad asadi
mehrdad asadi el 7 de Jul. de 2015
got it!
thanks

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by