How to plus two nan matrix

조회 수: 3 (최근 30일)
min wong
min wong 2017년 5월 16일
댓글: James Tursa 2018년 11월 28일
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

채택된 답변

James Tursa
James Tursa 2017년 5월 16일
c = a + b;
c(isnan(c)) = a(isnan(c));
c(isnan(c)) = b(isnan(c));
  댓글 수: 5
James Tursa
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;
min wong
min wong 2017년 5월 18일
Thanks !!

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Paulo Neto
Paulo Neto 2018년 11월 28일
How I can do this: c = (a + b)/b
Regards
  댓글 수: 3
Paulo Neto
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
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
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?

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by