MATLAB: Finding column # that contains an integer in a matrix

find indexmatrix

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

Best Answer

X = your matrix;
indices = find(any(X==5)); % columns that have the number 5 in them