How to avoid or delete Nan values in addtion?

1 次查看(过去 30 天)
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.

采纳的回答

madhan ravi
madhan ravi 2018-10-10
编辑:madhan ravi 2018-10-10
A=[2 NaN ; 3 NaN] %Edited
B=[NaN 4 ; NaN 5]
A(isnan(A))=0
B(isnan(B))=0
C=[A;B]'

更多回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by