MATLAB: How to make any math operation when there are NaN in data serial

nan data serial

How to make any math operation when there are NaN in data serial?
I'd like to make an test using in my data serial NaN…
For exemplo: I have 2 matrix (a and b) and I'd like of sum them!!!
Ex:
a=[1,2,3,NaN,5]
b=[1,2,3,8,5]
c=(a+b)
How can I to do?

Best Answer

Try these two different approaches:
a=[1,2,3,NaN,5]
b=[1,2,3,8,5]
cWithNans = a + b % c(4) will = nan
nonNanLocations = ~isnan(cWithNans) % Location of indexes that are good.
cwithoutNans = cWithNans(nonNanLocations)
% c(4) is skipped and new c(4) = old c(5)