How to avoid or delete Nan values in addtion?

1 visualización (últimos 30 días)
Shubham Mohan Tatpalliwar
Shubham Mohan Tatpalliwar el 10 de Oct. de 2018
Editada: Guillaume el 10 de Oct. de 2018
if i have2 matrix
A=[2 NaN ; 3 NaN]
B=[NaN 4 ; NaN 5]
I want C as
[2 4 ; 3 5 ]
edited by guillaume: Nan is not valid in matlab. NaN or nan is.

Respuesta aceptada

madhan ravi
madhan ravi el 10 de Oct. de 2018
Editada: madhan ravi el 10 de Oct. de 2018
A=[2 NaN ; 3 NaN] %Edited
B=[NaN 4 ; NaN 5]
A(isnan(A))=0
B(isnan(B))=0
C=[A;B]'
  3 comentarios
Shubham Mohan Tatpalliwar
Shubham Mohan Tatpalliwar el 10 de Oct. de 2018
Editada: Shubham Mohan Tatpalliwar el 10 de Oct. de 2018
Can i change Nan values to zero and then add both matrices?
that would be more clearer and easier i guess?
madhan ravi
madhan ravi el 10 de Oct. de 2018
Check the edited code

Iniciar sesión para comentar.

Más respuestas (1)

Guillaume
Guillaume el 10 de Oct. de 2018
If I understood correctly,
C = sum(cat(3, A, B), 3, 'omitnan')

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by