You can use find to search for nonzero elements in an array, but this requires a bit of arithmetic. From the documentation:
[row,col] = find(X, ...) returns row and column indices of nonzero entries in the X matrix. This syntax is especially useful when working with sparse matrices. If X is an N-dimensional array with N> 2, col contains linear indexes for the columns. For example, for a 5-by-3 array of X with a non-zero element in X (4,2,3), find returns 4 in the row and 16 in the column. That is (7 columns on page 1) + (7 columns on page 2) + (2 columns on page 3) = 16.
If the matrix M has dimensions axbxc , then the indices (i,j,k) for some value of x are equal to:
[row,col] = find(A==x); i = row; j = mod(col,b); k = ceil(col/b);
Pengone
source share