How to make NaN data an empty entry

I have a 2160 by 4320 data that has lots of NaN. How do I make matlab ignore the NaNs (i.e making them an empty entry, not zero) and still maintain the same size of the data size

 Respuesta aceptada

A=randi(500,5,5);
A(A<100)=nan
A = 5×5
138 207 415 446 134 NaN 437 153 NaN 449 119 443 141 127 NaN 294 235 NaN 336 149 NaN 155 235 314 264
Ac = num2cell(A)
Ac = 5×5 cell array
{[138]} {[207]} {[415]} {[446]} {[134]} {[NaN]} {[437]} {[153]} {[NaN]} {[449]} {[119]} {[443]} {[141]} {[127]} {[NaN]} {[294]} {[235]} {[NaN]} {[336]} {[149]} {[NaN]} {[155]} {[235]} {[314]} {[264]}
Ac(isnan(A)) = {[]}
Ac = 5×5 cell array
{[ 138]} {[207]} {[ 415]} {[ 446]} {[ 134]} {0×0 double} {[437]} {[ 153]} {0×0 double} {[ 449]} {[ 119]} {[443]} {[ 141]} {[ 127]} {0×0 double} {[ 294]} {[235]} {0×0 double} {[ 336]} {[ 149]} {0×0 double} {[155]} {[ 235]} {[ 314]} {[ 264]}
Ac is now the same size as A, but the nan entries have been made empty.

Más respuestas (1)

Matt J
Matt J el 5 de Dic. de 2021
It depends on the operation. If you are taking the maximum of each data colum, for example, the NaNs are already ignored, e.g.,
A=randi(500,5,5);
A(A<100)=nan
A = 5×5
156 367 474 104 134 395 166 128 NaN 108 478 360 196 392 387 160 150 NaN 439 190 336 NaN 219 148 330
maximum = max(A)
maximum = 1×5
478 367 474 439 387

6 comentarios

Opeyemi Kehinde
Opeyemi Kehinde el 5 de Dic. de 2021
I want to create a new variable of the same size and data but this new variable should show blanks/nothing in the places where nan occured. Something like find(isnan(var))=[]
Matt J
Matt J el 6 de Dic. de 2021
No, you can't do that. Some place holder to mark missing data will be present in any Matlab array type.
Walter Roberson
Walter Roberson el 6 de Dic. de 2021
Well it can be done if it is intended for display only, by constructing a character array and disp() that.
Opeyemi Kehinde
Opeyemi Kehinde el 8 de Dic. de 2021
Thanks for the help, but I don't think I can use it for a mathematical calculation (maybe multiplying with another matching data) in this cell format or plot a graph.
Walter Roberson
Walter Roberson el 8 de Dic. de 2021
Suppose that somehow you were able to create a numeric-like matrix that you could do mathematics with, and yet displayed some elements as blanks/nothing. What mathematical properties should be blank/nothing have? For example should [blank*2,5] have the blank be treated as the empty vector, and empty times 2 is empty, and horzcat([], 5) is the scalar 5 ??
Opeyemi Kehinde
Opeyemi Kehinde el 10 de Dic. de 2021
Ok thanks

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 5 de Dic. de 2021

Comentada:

el 10 de Dic. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by