Replace NAN in matrix with empty cells and reshape to matrix
이전 댓글 표시
I have a matrix X with several NAN values. I want replace the NAN with just blank cells, not zeros. Then I want to end up with a matrix. The problem is that it reshapes the matrix when I use this code
X(isnan(X))=[];
How can I replace the NAN with blanks and end up with the same matrix?
댓글 수: 8
Image Analyst
2018년 6월 27일
Matrices do not have cells - they have elements. Matrices cannot have "blank" elements or missing elements.
Cell arrays have cells. Which do you have?
Stef
2018년 6월 27일
@Stef: You have a choice between:
- using NaN to indicate missing data.
- using a logical mask (write your code to handle this).
- removing the data entirely (change the array shape).
- convert the data to a ragged array (e.g. a cell array, suitable for data arranged in vectors with the same start index and different end indices).
Stef
2018년 6월 28일
@Stef: If NaN already has a meaning then you could use a mask. This could be a separate logical array of the same size (recommended) or you could use some special values inside the data array (e.g. Inf, not recommended). As Image Analyst already wrote, matrices cannot have "spaces", and they must be rectangular.
Stef
2018년 6월 28일
Guillaume
2018년 6월 28일
Then use functions that ignore nans by e.g. using the 'omitnan' of mean (or sum, or ...) in your analysis. Without more details of your analysis it's difficult for us to give you advice.
Stef
2018년 6월 28일
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 NaNs에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!