Checking that array is in cell array

Let's say I have the following cell array:
c = {{[1],[2],[3]};%note this first cell of arrays contains only 1-dim arrays
{[1,2],[2,3],[1,3]}; %only 2-dim arrays
{[1,2,3]}} %only 3-dim arrays
And I want to know if all the subsets of [1,2,3] are in c{2} (which is another cell), how do I ask matlab if [1,2] is in c{2}? This is an inductive kind of cell array where I am adding cells c{k} if and only if all the subsets of a given set (in this example [1,2,3]) were already added to c. I am only stuck in the step of finding this logical value: TF = [1,2] in c{2}. So something like ismember that works with cell arrays that contain arrays.

 採用された回答

Walter Roberson
Walter Roberson 2020 年 6 月 13 日

1 投票

2 件のコメント

Juliana
Juliana 2020 年 6 月 13 日
Thank you! I ended up using
(ismember(1,cellfun(@(M) isequal(M, [1,2]), c{2})))
which gives me the true I was looking for :)
Walter Roberson
Walter Roberson 2020 年 6 月 13 日
any(cellfun(@(M) isequal(M, [1,2]), c{2}))

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

製品

リリース

R2019b

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by