Effacer les filtres
Effacer les filtres

How to avoid or delete Nan values in addtion?

1 vue (au cours des 30 derniers jours)
Shubham Mohan Tatpalliwar
Shubham Mohan Tatpalliwar le 10 Oct 2018
Modifié(e) : Guillaume le 10 Oct 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.

Réponse acceptée

madhan ravi
madhan ravi le 10 Oct 2018
Modifié(e) : madhan ravi le 10 Oct 2018
A=[2 NaN ; 3 NaN] %Edited
B=[NaN 4 ; NaN 5]
A(isnan(A))=0
B(isnan(B))=0
C=[A;B]'
  3 commentaires
Shubham Mohan Tatpalliwar
Shubham Mohan Tatpalliwar le 10 Oct 2018
Modifié(e) : Shubham Mohan Tatpalliwar le 10 Oct 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 le 10 Oct 2018
Check the edited code

Connectez-vous pour commenter.

Plus de réponses (1)

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

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by