Replace Nan with empty cell in table
조회 수: 33 (최근 30일)
이전 댓글 표시
I have created a table by concatenating two columns together as it runs row by row in a for loop. The output is as shown in the command window. How can I replace the 'Nan' with an empty cell value. I don't want to get rid of it because for that I can use the rmmissing function. I want to have that cell to remain empty so that when it's outputted as a final table it creates the spaces in between numbers.
댓글 수: 0
채택된 답변
dpb
2023년 2월 10일
편집: dpb
2023년 2월 14일
No can do unless convert the table variables to cell arrays; a double array cannot have anything other than numeric values. A MATLAB table data structure is NOT a spreadsheet although it superficially appears somewhat akin to one...
a=randi([2000 6999],12,1); a(2:2:end)=nan; b=a+1; % some very roughly similar data...
tT=table(a,b) % turn into a table
illustrates don't need a loop nor concatenation to do the first step...
If it really, really, really were important to not have the NaN values showing, one would have to do something like
a=string(a); b=string(b); % turn into nonumeric representations of numbers
a(ismissing(a))=""; b(ismissing(b))=""; % use blanks instead of <missing> indicator
tT=table(a,b)
is rough equivalent of the cell route; a string array can be the null string rather than missing. MATLAB will then display the double-quotes around the values as the visual type indication in the command window.
You would have to fprintf the values with formatting string to get them to look differently.
The cellstr route would be the same idea; it displays "the curlies" around cell values...
tT=addvars(tT,cellstr(tT.a),'After','b','NewVariableName','c')
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!