Replace NaN's in a cell array with blanks (not empty char/string)
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Dubstep Dublin
el 29 de Oct. de 2017
Comentada: Walter Roberson
el 29 de Oct. de 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 comentarios
Respuesta aceptada
Walter Roberson
el 29 de Oct. de 2017
mask = cellfun(@(C) isnumeric(C) && isscalar(C) && isnan(C), YourCell);
YourCell(mask) = {[]}; %guessing that "blank cells" means "empty array"
2 comentarios
Walter Roberson
el 29 de Oct. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre NaNs en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!