フィルターのクリア

Replace NaN's in a cell array with blanks (not empty char/string)

1 回表示 (過去 30 日間)
Dubstep Dublin
Dubstep Dublin 2017 年 10 月 29 日
コメント済み: Walter Roberson 2017 年 10 月 29 日
Hello, I am using R2015. I am reading my data using xlsread. I have a cell array of numbers/strings and NaN's. I need to replace NaN's with blank cells (not empty char/string).
Thanks :)

採用された回答

Walter Roberson
Walter Roberson 2017 年 10 月 29 日
mask = cellfun(@(C) isnumeric(C) && isscalar(C) && isnan(C), YourCell);
YourCell(mask) = {[]}; %guessing that "blank cells" means "empty array"
  2 件のコメント
Dubstep Dublin
Dubstep Dublin 2017 年 10 月 29 日
Thanks Walter.
Walter Roberson
Walter Roberson 2017 年 10 月 29 日
YourCell = cell(10,10);
for K = randperm(100,80); YourCell{K} = randi(5,randi(5),randi(5)); end
for K = randperm(100,20); YourCell{K} = char('A' + randi(10,1,randi(8))); end
for K = randperm(100,10); YourCell{K} = nan; end
CopyOfCell = YourCell;
mask = cellfun(@(C) isnumeric(C) && isscalar(C) && isnan(C), YourCell);
YourCell(mask) = {[]}; %guessing that "blank cells" means "empty array"
Now when I compare CopyOfCell to the modified YourCell I see that NaN has indeed been replaced by 0×0 double. I see no 0x0 char created.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by