Intersection of three and more arrays
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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
2018 年 11 月 15 日
My FEX returns the index of the arrays
8 件のコメント
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
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.
@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
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
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
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
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
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
