MATLAB: How to search for an array inside another array

arraysfindindexingMATLABmatrix manipulation

E.g: I have the following array:
a = [1 1; 1 2; 1 3; 1 4; 1 1; 1 4; 1 5];
I want to search for the occurance of each row of the following array inside "a":
b = [1 1; 1 4; 1 5]
The output should be the index location as follows:
idx = [1;5;4;6;7]
I tried the following code. But it does not work:
idx = [];
for i = size(b,1)
temp_idx = find(b(i,:) == a )
idx = [idx; temp_idx];
end
I there any way to do this ?

Best Answer

idx=find(ismember(a,b,'row'))