필터 지우기
필터 지우기

replace any nan value in the table by zero

조회 수: 25 (최근 30일)
wesso Dadoyan
wesso Dadoyan 2016년 5월 2일
댓글: Steven Lord 2021년 3월 11일
I have a 34420x229 table I want to replace any nan value in the table by zero. how can I do so ?

답변 (2개)

Robert Hamilton
Robert Hamilton 2016년 5월 16일
편집: Robert Hamilton 2016년 5월 16일
I've spent the better part of the day looking for an answer to this, and I've finally found some success with this format (so I figured I better share):
T{:,:}(isnan(T{:,:})) = 0
If all the columns are not numeric, the above will return an error. However, can use standard MATLAB range notations, e.g. T{:,10:end}(isnan(T{:,10:end})) = 0 to just search and replace in from the 10th column to the end of the table.
I do wish that ismissing() and standardizeMissing() would allow you the choice of what you wanted to put into the table for the missing value. In my case, it is histogram data pulled from a database, and if the measuring device didn't record data in a given bin, it doesn't bother to send a 0 to save on transmission costs. So, I needed to replace all the missing data -- the NaNs -- with 0s.
  댓글 수: 2
Richard Vergin
Richard Vergin 2018년 4월 28일
Thanks a lot this worked perfectly!
Peter Perkins
Peter Perkins 2018년 4월 30일
In more recent versions of MATLAB, fillmissing would be the thing to use.

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


Azzi Abdelmalek
Azzi Abdelmalek 2016년 5월 2일
  댓글 수: 10
Gabor
Gabor 2021년 3월 11일
Undefined function 'isnan' for input arguments of type 'table'
Steven Lord
Steven Lord 2021년 3월 11일
That's correct, the isnan function is not defined for table arrays. I recommend using fillmissing instead, which can handle both numeric and tabular arrays.

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

카테고리

Help CenterFile Exchange에서 Preprocessing Data에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by