Possible Duplicate:
MATLAB: Using interpolation to replace missing values (NaN)
I would like to interpolate data in multiple dimensions using the interpn command.
The problem is that the data contains NaN's. Therefore, in some dimensions, there are less than 2 datapoints which prevents matlab from interpolating. I would like interpn to return a NaN value in that case.
EXAMPLE: My data looks somehow likes this
val(:,:,1) =
-2.3810 -0.9365
NaN -0.6910
val(:,:,2) =
-2.3354 -0.9271
NaN -0.6859
Matlab gives an error when interpolating since there are inly NaN's in one dimension. I would like matlab to ignore this error and instead return NaN's form the interpn function.
You can introduce a go-between function which looks for NaNs.
So instead of calling interpn, you can call a function that does the following:
searches for NaN via any(any(any(isnan(val)))
if true returns NaN, otherwise it calls your function.
It's not clear if you want NaN for the entire interpn
, or just for a particular layer/dimension. If it's the latter, I'd appreciate it if you showed a bit more code.