Cellfun: check cell array for any value below 5, if yes return true

4 ビュー (過去 30 日間)
Moritz P.
Moritz P. 2015 年 5 月 24 日
編集済み: Stephen23 2015 年 5 月 25 日
Hi all, I have the following cell array
A = {4,5,6}
Is there a way to check whether any element is below 5 and return true if yes?
Been searching around but couldn't find any answers.
Cheers
  1 件のコメント
Stephen23
Stephen23 2015 年 5 月 25 日
編集済み: Stephen23 2015 年 5 月 25 日
This would be much easier to solve if you used a normal numeric array:
A = [4,5,6];
any(A<5)
This is essentially what Andrei Bobrov's second solution does: converts the cell array to a numeric array, then does the comparison.

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

採用された回答

Andrei Bobrov
Andrei Bobrov 2015 年 5 月 24 日
編集済み: Andrei Bobrov 2015 年 5 月 24 日
any(cellfun(@(x)x < 5,A))
or
any([A{:}] < 5)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by