フィルターのクリア

how to count more than 1 element in cell array?

2 ビュー (過去 30 日間)
alice
alice 2012 年 6 月 22 日
Hello
I have cell array data example. D = {[1 2 5];[1 2 4 6];[2 4 5 6];[2 5];[1 4 6]}
the answer is 3
I want to know how to calculate a frequency of [2 5] which occurs in D by not using loop.
thank you
  1 件のコメント
Walter Roberson
Walter Roberson 2012 年 6 月 22 日
[2 5] must be the only element? 2 and 5 must be adjacent? In that order or order is irrelevant?
Some of these possibilities I don't think can be done without at least an implicit loop using one of the *fun() functions.

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

採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 6 月 22 日
Can so?
out = sum(cellfun(@(x)all(ismember([2 5],x)),D));
  2 件のコメント
Ryan G
Ryan G 2012 年 6 月 22 日
Just beat me to it!
alice
alice 2012 年 6 月 22 日
thanks
it's work

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

その他の回答 (2 件)

Ryan G
Ryan G 2012 年 6 月 22 日
I think this may be close to what you are looking for.
freqElements = sum(cellfun(@(x) mean(ismember([2 5],x)) == 1,D));
  1 件のコメント
alice
alice 2012 年 6 月 22 日
thanks
it's work

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


alice
alice 2012 年 6 月 22 日
Oh thank you so much
Both answers are work!
  1 件のコメント
Walter Roberson
Walter Roberson 2012 年 6 月 22 日
cellfun() is really a loop.

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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by