# MATLAB: Searching for vector values in a matrix

indeciesMATLABmatrixvector

Hi, I have a vector with 3 specific values and I want to find their indices in a matrix.

• % Creating a sample matrixyourMatrix=reshape(1:15,5,3)yourMatrix =       1     6    11       2     7    12       3     8    13       4     9    14       5    10    15% Creating a sample vector with three values.yourVector=[1,7,14];% Now getting the row and cols of those values.[rows, cols]=ind2sub( size(yourMatrix), ...                      arrayfun(@(v) find(yourMatrix==v), ...                               yourVector(:)) )rows =       1       2       4cols =       1       2       3
linIndex=arrayfun(@(v) find(yourMatrix==v), yourVector(:))