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

1 次查看(过去 30 天)
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 个评论
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 CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by