Intersect several arrays

Version (1.15 KB) by Julia
Uses Matlab standard intersect function recursively to return the intersection of several arrays.


Updated 24 Jul 2009

View License

function [varargout] = intersect_several (varargin)
% function [varargout] = intersect_several (varargin)
% varargout{1} is the intersect vector
% varargout{i>1} are the indices of the various varargin (in their order)

numarr = length(varargin);
intersect_arr = varargin{1};
for i=1:numarr
intersect_arr= intersect(intersect_arr,varargin{i});
varargout{1} = intersect_arr;
for i=1:numarr
[intersect_arr, temp,varargout{i+1}]= intersect(intersect_arr,varargin{i});

Cite As

Julia (2023). Intersect several arrays (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2008b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes