finding column # that contains an integer in a matrix
3 views (last 30 days)
Show older comments
mehrdad asadi
on 7 Jul 2015
Commented: mehrdad asadi
on 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
0 Comments
Accepted Answer
James Tursa
on 7 Jul 2015
Edited: James Tursa
on 7 Jul 2015
X = your matrix;
indices = find(any(X==5)); % columns that have the number 5 in them
4 Comments
James Tursa
on 7 Jul 2015
indices = find(any(X==5,2)); % rows that have the number 5 in them
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!