Having a hard time with this seemingly easy concept

I have a data array,X, of 1958x36x72

1958 is the time dimension

36 is lat dimension

72 is long dimension

There are NaNs in both the temporal and spatial sense

What I have done is set a 50% criterion on the data to keep. In other words, if over the course of the time domain, there is a NaN less than 50% of the time in the lat/long index, I keep the data. If not, I re-write it as a NaN.

As such, I have a new data array,Y, where values are identical to X if NaNs in the temporal sense are less than 50%. However, the grid spaces where NaNs exist over 50%, they are now all NaNs at that gridpoint.

For the grid points that meet my threashold, I want to interpolate the data to fill in those missing points that currently have NaNs (only in the arrays that have NaNs less than 50% of the time)

However, I am not having much luck in terms of coding this up. I am using Matlab

Here are two recent cases where I have been playing around with this

1)

-------------------------------

2)

I feel I am having a hard time grasping understanding which function to use. If anyone has any insight or experience along these lines, it would be greatly helpful

I have a data array,X, of 1958x36x72

1958 is the time dimension

36 is lat dimension

72 is long dimension

There are NaNs in both the temporal and spatial sense

What I have done is set a 50% criterion on the data to keep. In other words, if over the course of the time domain, there is a NaN less than 50% of the time in the lat/long index, I keep the data. If not, I re-write it as a NaN.

As such, I have a new data array,Y, where values are identical to X if NaNs in the temporal sense are less than 50%. However, the grid spaces where NaNs exist over 50%, they are now all NaNs at that gridpoint.

**Here is what I am trying to achieve:**For the grid points that meet my threashold, I want to interpolate the data to fill in those missing points that currently have NaNs (only in the arrays that have NaNs less than 50% of the time)

However, I am not having much luck in terms of coding this up. I am using Matlab

Here are two recent cases where I have been playing around with this

1)

Code:

```
time = 1:1:1958;
temp_anom_crit_interp = interp2(time,temp_anomlay_criterion,time,'spline')
```

2)

Code:

```
for t= 1:1958
for i = 1:36
for j = 1:72
temp_anom_crit_interp(t,i,j) = interp(temp_anomlay_criterion(t,i,j),r); %have NO idea what to use for r in my case
end
end
end
```

I feel I am having a hard time grasping understanding which function to use. If anyone has any insight or experience along these lines, it would be greatly helpful

Last edited by a moderator: