Replace Nan with blank in a TABLE
조회 수: 20 (최근 30일)
이전 댓글 표시
Hello!
I have a table thant contains strings, numbers and NaNs and I have to replace the Nans with blanks.
How can I do?
Thank you
댓글 수: 0
답변 (1개)
Walter Roberson
2021년 2월 10일
편집: Walter Roberson
2021년 2월 10일
You need to iterate over all of the variables, find the ones that are numeric, and if the variable contains nan, then replace the variable with the formatted content of the numeric value, putting in blanks where-ever the nan were.
table() were not designed for presentation purposes, no Mathworks-provided function for this purpose.
YourTable = table([1;2;3;nan;5], {'a';'b';'c';'d';'e'}, [nan;12;13;14;15], rand(5,1))
YourTable = convertvars(YourTable, @isnumeric, @nanblank)
function output = nanblank(values)
mask = isnan(values);
if nnz(mask)
output = string(values);
output(mask) = "";
output = char(output);
else
output = values;
end
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!