Tue 25 May 2010 01:45:05 PM UTC, comment #3:
In your patch, you have
+ for k = (1:columns (a))(any (isnan (a)))
+ ok = ! isnan (a(:,k));
+ a(!ok,k) = spline (x(ok), a(ok,k), x(!ok));
+ endfor
+
+ if (any (isnan (a)))
+ for k = 1:size(a,2)
+ ok = (! isnan (a(:,k)));
+ a(!ok,k) = spline (x(ok), a(ok,k), x(!ok));
+ endfor
+ endif
It looks like you are doing the same operation twice. Is that intended? If so, then it might be good to use a temporary variable to avoid computing this result more than once. Possibly also for the computation of the OK vectors.
Is the
if (any (isnan (a))
doing what you expect if A is a matrix? For example:
a = [1,2,3;4,NaN,6];
isnan (a) ==> [0,0,0;0,1,0]
any (isnan (a)) ==> [0,1,0]
and in an IF condition, this will be considered false.
|
Tue 25 May 2010 04:52:57 AM UTC, comment #1:
From your Changeset:
+ if (any (isnan (a)))
+ for k = 1:size(a,2)
+ ok = (! isnan (a(:,k)));
+ a(!ok,k) = spline (x(ok), a(ok,k), x(!ok));
+ endfor
+ endif
This will iterate over all of the columns (1:size(a,2)), including the ones which don't have NaNs in them. It would be more efficient to operate only on the columns with NaNs in them.
For example:
for k = (1:columns (a))(any (isnan (a)))
ok = ! isnan (a(:,k));
a(!ok,k) = spline (x(ok), a(ok,k), x(!ok));
endfor
It is a little opaque but the key is that it creates a range from 1 to the number of columns and then uses the isnan function to index into it so that only columns with NaNs will get processed.
|