Count elements not including blank entries in a cell array

43 ビュー (過去 30 日間)
Maria
Maria 2014 年 7 月 19 日
コメント済み: Maria 2014 年 7 月 20 日
I have a cell-array and I am trying to count the elements for each row that have a value and not 'Nan' or '[]'. For example:
Input: Output:
18 76 [] 76 28 28 5
22 [] [] 123 123 123 4
25 12 12 12 [] [] 4
The code I am using is the following, and I tried different variations:
output=numel(input(size(input(1,:),1),:))-sum(isnan(input(size(input(1,:),1),:))
I believe the functions themselves (numel, sum, isnan) are ok, at least they work, but the problem is that I only get the output either for the first row, or the last row, so something is wrong for sure. Can someone help? Thanks

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 7 月 19 日
A={18 76 [] 76 28 28
22 [] [] 123 123 123
25 12 12 12 [] []}
idx=sum(~cellfun(@isempty,A),2)
  3 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 7 月 19 日
No, the result is
idx=[5
4
4]
Maria
Maria 2014 年 7 月 20 日
My bad, I was tired and I was doing a mistake in my code without noticing. Thanks!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by