MATLAB: How to compare two rows of an array withot for loop

compare

Hi! I want to compare two rows of an array. I want to do this:
I hace a = [1 NaN 2 NaN;[2 NaN NaN 3];
I want to create another array without using for loop iteration and obtain the next array
–> If both have a value I want to obtain the mean value of them.
–> if one of them have NaN I want to obtain the number
–> If both have NaN I want to delete it
I want to obtain this:
c = [1,NaN,2,3]

Best Answer

Try this
a = [1 NaN 2 NaN];
b = [2 NaN NaN 3];
c = nanmean([a; b])
Result:
c =
1.5000 NaN 2.0000 3.0000