Replace NAN in matrix with empty cells and reshape to matrix
Mostra commenti meno recenti
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 Commenti
Image Analyst
il 27 Giu 2018
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
il 27 Giu 2018
@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
il 28 Giu 2018
@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
il 28 Giu 2018
Guillaume
il 28 Giu 2018
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
il 28 Giu 2018
Risposte (0)
Categorie
Scopri di più su NaNs in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!