MATLAB: How to compare to matrices with each other

differential equationsif statementmatricessearch

Hi Everyone,
I have two different matrices with diffrent sizes. for example one of them is 1000*3 and the other one is 5000*3.
How can I select/compare the line (I mean 1000 rows of these 5000 rows will be the same in these two matrices) and keep it in another matrice?
box1=cut2d(:,2:4);
box2=rombohedral(:,1:3);
if box1==box2
rombohedral2d=rombohedral;
end
The if part is not working.

Best Answer

box1=cut2d(:,2:4);
box2=rombohedral(:,1:3);
[index1,index2] = ismember(box1,box2,'rows');
% index2 holds the indices of the rows that are also in box1
rombohedral2d=rombohedral(index2,:); % I assume you want all the columns, not only 3, right?
% if you want only those 3 columns, use:
% rombohedral2d=rombohedral(index2,1:3);