Multiple or partial INTERSECT function

Version 1.1.0.0 (1.73 KB) by Jeremy
INTERSECTN allows > 2 inputs and finds partial intersects! Much more flexible than intersect alone!
372 Downloads
Updated 11 Mar 2011

View License

% INTERSECTN functions similarly to INTERSECT, but has some added
% flexibility. For example, if you input three arrays and want to find
% items that are in at least two of them, INTERSECT is incapable of doing
% this, but INTERSECTN will do it.
%
% OUT = INTERSECTN(IN1,IN2,...,MATCHES)
%
% Inputs: IN1,IN2,... are cell arrays of strings or numerical vectors.
% MATCHES is a scalar, the number of matches that are required.
%
% For example, if you have three sets of fruit names, and you want to
% return any fruits that show up in at least two of these sets, use:
% OUT = INTERSECTN(IN1,IN2,IN3,2)
%
% Example:
% fruit{1} = {'apple','banana','cherry','orange'};
% fruit{2} = {'apple','cherry','lemon','tangerine'};
% fruit{3} = {'apple','lemon','lime','peach'};
% fruit{4} = {'apple','lemon','orange','coconut'};
%
% out = intersectn(fruit{:},4)
% returns: 'apple'
%
% out = intersectn(fruit{:},3)
% returns: {'apple','lemon'}
%
% out = intersectn(fruit{:},2)
% returns: {'apple','cherry','lemon','orange'}

Cite As

Jeremy (2024). Multiple or partial INTERSECT function (https://www.mathworks.com/matlabcentral/fileexchange/30725-multiple-or-partial-intersect-function), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Characters and Strings in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.1.0.0

Updated file description.

1.0.0.0