find matching rows in matrices

B
Bexley · Dec 24, 2020 · 1.9K views
Question
I want to find which rows in two matrices that are matching. If I for example have A =   1 2 4 5 9 7 1 2 6 5 and   B = 2 5 1 2 9 2 1 2 I would like a result like index_A=[1 4] index_B=[2 4]. Any idea how to solve this?
Expert Answer
Profile picture of John Williams
John Williams PhD Expert
Answered Aug 31, 2026

Use the 2nd and 3rd returned arguments in 'intersect':

 

 [~,index_A,index_B] = intersect(A,B,'rows');
100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!