find element in array

2 ビュー (過去 30 日間)
NA
NA 2018 年 10 月 18 日
編集済み: Stephen23 2018 年 10 月 18 日
I have
E=[1 2;1 5;2 3;2 4;2 5;3 4;4 5;4 7;4 9;5 6;6 11;6 12;6 13; 7 8;7 9;9 10;9 14;10 11;12 13;13 14]
and
C={[1,2,4,5],[1,2,4,5,6,9,10,11],[1,2,4,5,6,13,13]}
I want to write a code that give me this result:
{[1,2;1,5;2,5;4,5],[1,2;1,5;2,4;4,9;9,10;5,6;6,11],[1,2;1,5;2,4;4,9;5,6;6,13;9,14;13,14]}

採用された回答

Bruno Luong
Bruno Luong 2018 年 10 月 18 日
編集済み: Bruno Luong 2018 年 10 月 18 日
Not sure how you get the result, but here is an attempt
Data
E=[1 2;1 5;2 3;2 4;2 5;3 4;4 5;4 7;4 9;5 6;6 11;6 12;6 13; 7 8;7 9;9 10;9 14;10 11;12 13;13 14]
C={[1,2,4,5],[1,2,4,5,6,9,10,11],[1,2,4,5,6,13,13]}
Code
CC = cellfun(@(s) E(all(ismember(E,s),2),:), C, 'unif', 0);
Result:
>> CC{:}
ans =
1 2
1 5
2 4
2 5
4 5
ans =
1 2
1 5
2 4
2 5
4 5
4 9
5 6
6 11
9 10
10 11
ans =
1 2
1 5
2 4
2 5
4 5
5 6
6 13

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Types についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by