Hi, is it possible in matlab to find intersection of three and more arrays and index of intersection value in each of three array? Like [C,ia,ib] = intersect(A,B) but for three or more arrays.

 採用された回答

Bruno Luong
Bruno Luong 2018 年 11 月 15 日

0 投票

My FEX returns the index of the arrays

8 件のコメント

Baisseyev Miram
Baisseyev Miram 2018 年 11 月 15 日
Thank you, it gives good result, but not i wanted, i think i asked incorretly. Is it possible with you function find their first intersection and its index? for example a=[5,6,4,7,8], b= [7,8,6,5,4] and c=[4,8,5,6,7], first intersection of three arrays is 6
Bruno Luong
Bruno Luong 2018 年 11 月 15 日
編集済み: Bruno Luong 2018 年 11 月 15 日
What is the first intersection of
a = [5 6] and b = [6 5] ?
Sorry I don't know what is a "first intersection".
Intersection is common elements, an element of the intersection can appear anywhere in the sets, e.g. above, it can appears fisrt in one set and last in other set.
If you want to figure out what is the first in a particular set, sort the index output to find the lowest.
jonas
jonas 2018 年 11 月 15 日
編集済み: jonas 2018 年 11 月 15 日
@Baisseyev,
In your example, would not 5 and 6 both be the "first intersection", granted that you scan each array from left to right and find the first intersection.
Baisseyev Miram
Baisseyev Miram 2018 年 11 月 15 日
i have 7 arrays, each contain elemnts from 1 one to 60 in different order, i want to find first element which will be repeated in this 7 arrays for example it is 31 but in first array its index 5, in second 15 and so on so i want find this number(31) and its indexes in this 7 arrays (5, 15 ...)
Bruno Luong
Bruno Luong 2018 年 11 月 15 日
Please define "first element". Your prose is so far meaningless for those who read.
Nobody knows why you pick 31 as the first of the 7 arrays which nobody know the contents.
As with above: why you pick 6 as the first for : a=[5,6,4,7,8], b= [7,8,6,5,4] and c=[4,8,5,6,7]?
To me the first intersection in a is 5; in b is 7; in c is 4.
Baisseyev Miram
Baisseyev Miram 2018 年 11 月 15 日
31 is an example, in a=[5,6,4,7,8], b= [7,8,6,5,4] and c=[4,8,5,6,7], is the first to be repeated in a, b, c it like this if you look at first element in each array it is 5, 7, 4 then 6,8,8, then 4,6,5 then 7,5,6 till here 5 (here mistake not 6) was the first element which was repeat in all three arrays, so i want to find this 5 and indexes in this arrays. Maybe here needed another function, not intersection
Bruno Luong
Bruno Luong 2018 年 11 月 15 日
編集済み: Bruno Luong 2018 年 11 月 15 日
IIUC, what you want is the common element with the lowest max indexes over all the set.
a = [5,6,4,7,8],
b = [7,8,6,5,4],
c = [4,8,5,6,7],
sets = {a,b,c};
nset = length(sets);
idx = cell(1,nset);
[s,idx{:}] = mintersect(sets{:});
idx = cat(1,idx{:});
imax = accumarray(repmat((1:length(s))',nset,1),idx,[],@max);
[~,iminmax] = min(imax);
firstelem = s(iminmax) % returns 5
Baisseyev Miram
Baisseyev Miram 2018 年 11 月 16 日
Yes, thank you very much for spending your time

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by