I have a 54x8 cell array that contains only strings. Most of these strings represent numbers and I would like to detect which cells are NaN.
One possibility would simply be to replace all NaN with ' ' or to check whether each d{i,j} == NaN.
Thanks

 採用された回答

Walter Roberson
Walter Roberson 2015 年 5 月 26 日

2 投票

cellfun(@(C) any(isnan(C(:)), YourCell)
However in your situation you could probably go with
cellfun(@isnumeric, C)
Oh wait, when you say NaN, do you mean the string 'NaN' ? If so then
cellfun(@(C) strcmp(C, 'NaN'), C)

6 件のコメント

SG
SG 2015 年 5 月 26 日
Yes, I meant the string 'NaN'. However, I am not sure what that statement is doing. Is it returning anything?
Walter Roberson
Walter Roberson 2015 年 5 月 26 日
Ah right, should be cellfun(@(C) strcmp(C,'NaN'), d) for testing cell array d.
SG
SG 2015 年 5 月 26 日
yes, but that gives a matrix with 0s and 1s at corresponding indexes. Is there a simpler way to check a given d{i,j}? E.g.
for i=1:54
for j=1:8
if (d{i,j} == 'NaN')
%statement
end
end
end
G H
G H 2017 年 7 月 8 日
Not work for me. (2016b)
Answer: Matrix dimensions must agree.
Walter Roberson
Walter Roberson 2017 年 7 月 8 日
G H are you comparing numeric nan or string 'NaN'
beginner94
beginner94 2018 年 12 月 18 日
編集済み: beginner94 2018 年 12 月 18 日
Hello,
@WalterRoberson:
Is there a way to use this
cellfun(@(ds) strcmp(ds, 'NaN'), ds))
when the cell elements are not aligned but below each other?
Thank you!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

質問済み:

SG
2015 年 5 月 26 日

編集済み:

2018 年 12 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by