![]() |
mean of two matrixes with Nans, element per element
<p>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 <code>nanmean</code>, since that doesn't sum element per element.</p>
<p>Simplified example:</p> <pre><code>A= [1 1 1 1 1 1 1 nan 1]; B=[3 3 3 3 3 3 3 3 3]; </code></pre> <p>Result I want :</p> <pre><code>C= [2 2 2 2 2 2 2 3 2]; </code></pre> <p>So the nan is ignored.</p> <p>One way to sum element per element I found on <a href="https://nl.mathworks.com/matlabcentral/answers/366304-how-to-sum-up-multiple-matrices-element-by-element" rel="nofollow noreferrer">https://nl.mathworks.com/matlabcentral/answers/366304-how-to-sum-up-multiple-matrices-element-by-element</a> </p> <pre><code>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) </code></pre> <p>BUT this isn't the nansum. How can I do this not taking into account the nans?</p> [url=https://stackoverflow.com/questions/59033516/mean-of-two-matrixes-with-nans-element-per-element]More answer...[/url] |
所有时间均为北京时间。现在的时间是 10:38。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.