Replace missing cell entries without replacing whitespaces.

조회 수: 23 (최근 30일)
Niek W
Niek W 2021년 4월 7일
댓글: Niek W 2021년 4월 7일
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!

채택된 답변

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

추가 답변 (1개)

Monika Jaskolka
Monika Jaskolka 2021년 4월 7일
for i = 1:numel(A)
if ismissing(A{i})
A{i} = 'REPLACED';
end
end
  댓글 수: 1
Niek W
Niek W 2021년 4월 7일
Hi Monika, your solution works. However someone on stackexchange was slightly faster, so I've marked that answer as Accepted.
Thanks anyway!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by