how to count more than 1 element in cell array?
2 次查看(过去 30 天)
显示 更早的评论
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
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.
采纳的回答
更多回答(2 个)
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));
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!