Intersect2

バージョン 1.0.0.0 (771 Bytes) 作成者: Suri Like
Finds the intersection (common elements) of several (more than two) arrays
ダウンロード: 1.7K
更新 2008/3/31

ライセンスがありません

In MATLAB, there is a command called "intersect", which finds the set intersection (common elements) of two vectors. However, this command doesn't work if I want to compare more than two vectors and find out their intersection. Therefore, I decided to write this function which is called "intersect2". It can find the common elements of any number of 1D numeric arrays of the same or different sizes and returns an array consisting of only those elements.

INPUT:
The input variable "cell" has to be a cell array, with each cell occupied by an 1D numeric array. For example, if you want to find the intersection (common elements) of the following three arrays
a = [ 1 3 4 6 8 9 ];
b = [ 3 1 0 8 6 4 ];
c = [ 7 8 1 9 3 4 ];,
you need to first put all of them into a cell array, i.e.
cell = {a, b, c};
Then you could use "cell" as the input variable to this function, i.e.
result = intersect2(cell);

OUTPUT:
The output of this function is simply an array consisting of elements that are common to all the arrays stored in "cell". For the particular case in the example above, the output would be
result = [ 1 3 4 8 ];
Also note that the numbers in the result are sorted in ascending order.

引用

Suri Like (2026). Intersect2 (https://jp.mathworks.com/matlabcentral/fileexchange/19359-intersect2), MATLAB Central File Exchange. 取得日: .

MATLAB リリースの互換性
作成: R2007a
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
カテゴリ
Help Center および MATLAB AnswersMatrices and Arrays についてさらに検索
バージョン 公開済み リリース ノート
1.0.0.0