Replace missing cell entries without replacing whitespaces.

I'm reading an excel file using readcell, and all empty cells are imported as 'missing'.
I would like to replace the missing, and i found the following suggestions (cellfun+anonymous function)
However, this solution also marks whitespaces as missing and replaces them
A = {1, 'test123', 2, 1, 'texthere';2, 'test456', 3 ,4, missing;...
3, 'test789', missing, 1, 'text with spaces'}
A(cellfun(@(x) any(ismissing(x)), A)) = {'REPLACED'}
In this example, I would like 'text with spaces' to be left alone, and only to replace the actual 'missing' cells. How do I achieve this?
Thanks!

 Accepted Answer

Solved by rinkert: https://stackoverflow.com/questions/66985871/matlab-replace-missing-cell-entries-without-replacing-whitespaces
A(cellfun(@(x) isa(x,'missing'), A)) = {'REPLACED'}

More Answers (1)

for i = 1:numel(A)
if ismissing(A{i})
A{i} = 'REPLACED';
end
end

1 Comment

Hi Monika, your solution works. However someone on stackexchange was slightly faster, so I've marked that answer as Accepted.
Thanks anyway!

Sign in to comment.

Categories

Find more on Data Import and Analysis in Help Center and File Exchange

Products

Release

R2019b

Asked:

on 7 Apr 2021

Commented:

on 7 Apr 2021

Community Treasure Hunt

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

Start Hunting!