MATLAB: Use griddedinterpolant to interpolate over missing values

griddedinterpolantinfinterpolationMATLABmissing valuesnanspikes

I would like to use griddedInterpolant to interpolate over datapoints that I need to discard from an N-dimensional matrix. Specifically, the undesirable values represent "spikes" in my data set that I have identified and need to remove. I thought that this would be very easy and fast to accomplish with griddedInterpolant, but I can't seem to figure out the syntax.
Here's an example. Let's say my data is in matrix A, which has dimensions [x y z]. Then I have another logical matrix isSpike of the same dimensions [x y z]. I thought I could simply type:
[X1, X2, X3] = ndgrid(1:x, 1:y, 1:z);
G = griddedInterpolant(X1(~isSpike), X2(~isSpike), X3(~isSpike), A(~isSpike), 'linear');
One could simply read this as "make a griddedInterpolant object centered on each non-spike element in my original dataset." Then, I thought I could simply get the interpolated data using:
B = G(X1, X2, X3);
Simple, right? However, I get an error when calling the griddedInterpolant command in this manner:
Error using griddedInterpolant
The number of input coordinate arrays does not equal the number of dimensions (NDIMS) of these arrays.
Could this be due to the behavior Matlab takes when one uses an N-dimensional logical indexing? For example, if I try:
test = X1(~isSpike);
test is returned as a vector having dimensions [1 (prod(x, y, z) – sum( isSpike ))]. In other words, it is transformed into a 1 dimensional vector array, and this cannot have the same dimensions as the original 3D matrix, since there are now fewer elements.
Regardless of the cause, does anyone have any suggestions on how to work around this?