Removing NaNs in a struct array

11 visualizaciones (últimos 30 días)
John Kelley
John Kelley el 15 de En. de 2019
Comentada: madhan ravi el 16 de En. de 2019
I have a struct array that is 15X1000X1000. There are random NaN's scattered throughout the data in this struct and I would like to replace these with random values between 1 and 10. I have tried writng an if statement to do it but the if cannot handle the NaN. How should i approach this.
  3 comentarios
John Kelley
John Kelley el 15 de En. de 2019
It is actully a 15x1000x1000 matrix not a struct array. Would the approach be differnet for the matrix
madhan ravi
madhan ravi el 16 de En. de 2019
Do you want to remove nan rows or columns or pages??

Iniciar sesión para comentar.

Respuestas (1)

Stephan
Stephan el 15 de En. de 2019
Editada: Stephan el 15 de En. de 2019
Hi,
for a matrix A in R2018b use:
A(isnan(A)) = randi(10,1,sum(isnan(A),'all'))
Best regards
Stephan
  1 comentario
Guillaume
Guillaume el 15 de En. de 2019
Instead of sum(isnan(A), 'all') you could use nnz(isnan(A)) which is shorter and works in any version of matlab. It's possibly faster as well.

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by