I want to have the nanmean of two matrixes element per element. I don't seem to be able to do it using the function nanmean
, since that doesn't sum element per element.
Simplified example:
A= [1 1 1
1 1 1
1 nan 1];
B=[3 3 3
3 3 3
3 3 3];
Result I want :
C= [2 2 2
2 2 2
2 3 2];
So the nan is ignored.
One way to sum element per element I found on https://nl.mathworks.com/matlabcentral/answers/366304-how-to-sum-up-multiple-matrices-element-by-element
A(:,:,1)=randi([1 3],100,100);
A(:,:,2)=randi([1 3],100,100);
A(:,:,3)=randi([1 3],100,100);
A(:,:,4)=randi([1 3],100,100);
B=zeros(size(A,1),size(A,2));
for i=1:size(A,3)
B=B+A(1:size(A,1),1:size(A,2),i);
end
disp(B)
BUT this isn't the nansum. How can I do this not taking into account the nans?
More answer...