MATLAB: Extracting column no. from an array based on values in another array

arraycolumnmatrix

Hi,
I have an array: Array1
and another array(sub set of above one): Array2
I want to know the position of elemnts of Array2 in Array1.
For Ex:
Input:
Array1 – [A,B,C,D,E,F]
Array2 – [B,D]
Output:
2,4

Best Answer

Use ismember
Array1 = {'A','B','C','D','E','F'}
Array2 = {'B','D'}
[~,ii] = ismember(Array2,Array1)