intersectN2(L1,L2) finds all N1x2 N2x2 common pairs as well as respective indices to common pairs.
Function intersectN2 finds all common pairs of input vectors aL1_ and aL2_
call: [U,n1,n2]=intersectN2(L1,L2)
L1 : N1x2 or 2xN1 vector
L2 : N2x2 or 2xN2 vector
U is a N3x2 vector containing all common elements
n1 : index vector common elements L1(n1,:) in L1.
n2 : index vector common elements L2(n2,:) in L2.
the following conditions are staisfied: isequal(L1(n1,:),L2(n2,:))
isequal(U,L1(n1,:),L2(n2,:))
If there are no common errors U n1 and n2 are null contents.
Input Output Restrictions: 1.- The input vectors have to be of dimensions N1x2 N2x2 or 2xN1 2xN2
2.- Strict number of input arguments, only 2, no more than 2 input vectors
3.- Strict amount of output arguments, only 3, no more than 3
Test example:
clear all;close all;clc
L1=randi([-5 5],10,2)
L2=randi([-5 5],20,2)
[U,n1,n2]=intersectN(L1,L2)
U
L1(n1,:)
L2(n2,:)
isequal(L1(n1,:),L2(n2,:))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Author: John Bofarull, any comments to improve this function are welcome
at jgb2012@sky.com or through the Mathworks forum to John BG jgb2012@sky.com
1st release: April 8th 2018.
Cite As
John BG (2024). intersectN2(L1,L2) finds all N1x2 N2x2 common pairs as well as respective indices to common pairs. (https://www.mathworks.com/matlabcentral/fileexchange/66822-intersectn2-l1-l2-finds-all-n1x2-n2x2-common-pairs-as-well-as-respective-indices-to-common-pairs), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 | added comment regarding strict input output number of arguments; 2 and only 2 input arguments, 3 and only 3 output arguments. Removed comment lines |