Replace NaN's in a cell array with blanks (not empty char/string)
7 views (last 30 days)
Show older comments
Dubstep Dublin
on 29 Oct 2017
Commented: Walter Roberson
on 29 Oct 2017
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 :)
0 Comments
Accepted Answer
Walter Roberson
on 29 Oct 2017
mask = cellfun(@(C) isnumeric(C) && isscalar(C) && isnan(C), YourCell);
YourCell(mask) = {[]}; %guessing that "blank cells" means "empty array"
2 Comments
Walter Roberson
on 29 Oct 2017
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.
More Answers (0)
See Also
Categories
Find more on NaNs in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!