MATLAB: How to extract complete rows of data from a matrix based on the intersection of a matrix with different column dimensions

extract rows of dataintersectMATLAB

I have a 2891 x 3 matrix, A = [LATi,1 LONi,2 STATIONIDi,3] for i=1:2891 locations where I know I have a complete data record of ocean data over multiple decades.
I want to use the i=1:2891 locations in the ocean [LATi,1 LONi,2] from A to extract complete rows of data from a second matrix, B = [LATm,1 LONm,2 STATIONIDm,3 DATA1m,4, DATA2m,5…] with different dimensions, 5090 x 41 double where the LAT and LON match matrix A.
I tried using intersect but I can only figure out how to return the common LAT and LON values of A and B as a new 2891 x 2 matrix, C.
I tried a variety of for loops and ismember but got lost and came back to where I started:
[C] = intersect(B(:,1:2),A(:,1:2),'rows');

Best Answer

[isinA, whichArows] = ismember(B(:, [1 2]), A(:, [1 2]), 'rows');
filteredB = B(isinA, :); %I assume this is the output you want
usedArows = A(whichArows, :); %maybe you also want this. If not, don't bother getting the 2nd output of ismember