On Sat, Dec 19, 2009 at 12:27 PM, Søren Hauberg
<address@hidden> wrote:
lør, 19 12 2009 kl. 12:02 -0500, skrev Naveen Garg:
> I would like to do element wise addition over matrices while skipping
> NaN values. there is nansum, but it does column wise addition within a
> matrix.
I don't quite follow what you mean by "skipping" NaN values. Do you
simply want to let NaN's work like zeros? If so, you should be able to
do something like (untested code)
a (isnan (a)) = 0;
b (isnan (b)) = 0;
c = a + b;
Søren
sort of.
a_fixed = a;
a_fixed(isnan(a)) = 0;
b_fixed = b;
b_fixed(isnan(b)) = 0;
c = a_fixed.+b_fixed;
c(and(isnan(a), isnan(a))) = NaN
works.
sorry for the double post, but someone also posted a solution using nansum here: http://stackoverflow.com/questions/1933455/matrix-addition-skipping-nan-values
by the way, numpy has a multidimensional version of the label function. I will translate as soon as i need to use it in octave.
Thanks.