how to count more than 1 element in cell array?

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

[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일

2 개 추천

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일

1 개 추천

I think this may be close to what you are looking for.
freqElements = sum(cellfun(@(x) mean(ismember([2 5],x)) == 1,D));
alice
alice 2012년 6월 22일

0 개 추천

Oh thank you so much
Both answers are work!

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2012년 6월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by