How to plus two nan matrix
1 次查看(过去 30 天)
显示 更早的评论
If my two matrix are
a=3*3,b=3*3,c=3*3
a=[1 2 3,4 5 nan,7 nan 9]
b=[nan 3 3,4 5 6,nan 8 9]
c=a+b
Is that possible that c=[1 5 6,8 10 6,7 8 18]
How to calculate?
Thanks
0 个评论
采纳的回答
James Tursa
2017-5-16
c = a + b;
c(isnan(c)) = a(isnan(c));
c(isnan(c)) = b(isnan(c));
5 个评论
James Tursa
2017-5-17
Depending on what you want to have happen to the "NaN" spots, I am guessing you will want either
c = (a + b)/2;
c(isnan(c)) = a(isnan(c));
c(isnan(c)) = b(isnan(c));
or
c = (a + b)/2;
c(isnan(c)) = a(isnan(c))/2;
c(isnan(c)) = b(isnan(c))/2;
更多回答(2 个)
Paulo Neto
2018-11-28
3 个评论
Paulo Neto
2018-11-28
I'm considering a and b as arrays:
a=3*3,b=3*3,c=3*3
a=[1 2 3,4 5 nan,7 nan 9]
b=[nan 3 3,4 5 6,nan 8 9]
To calculate c = a + b, I'm using your routine:
c(isnan(c)) = a(isnan(c));
c(isnan(c)) = b(isnan(c));
and results in c=[1 5 6,8 10 6,7 8 18]
But I need to calculate: (a+b)./b, can I use the same method?
James Tursa
2018-11-28
What would you want the individual result to be if "a" is NaN, and if "b" is NaN?
Paulo Neto
2018-11-28
I'm considering a and b as arrays:
a=3*3,b=3*3,c=3*3
a=[1 2 3,4 5 nan,7 nan 9]
b=[nan 3 3,4 5 6,nan 8 9]
To calculate c = a + b, I'm using your routine:
c(isnan(c)) = a(isnan(c));
c(isnan(c)) = b(isnan(c));
and results in c=[1 5 6,8 10 6,7 8 18]
But I need to calculate: (a+b)./b, can I use the same method?
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NaNs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!