필터 지우기
필터 지우기

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));

alice
alice 2012년 6월 22일
Oh thank you so much
Both answers are work!

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by