I think it would be easier to use griddedInterpolant as below, as well as more memory-conserving. I assume throughout that latitudes vary row-to-row while longitude varies column-to-column. This appears to be your convention in your posted code. I also assume that it truly is your intention that all mask(:,:,day) are identical to mask50, in which case you are repeating the same interpolation operation for each day unnecessarily. Thus, I have removed the creation of m50m from the loop.
Do not make matrices latrep,lonrep of replicated longitudes and latitudes unless you need them for something else. You certainly don't need them for interpolation. In the following code, I use the original vectors of lats and lons. If REF_lat,REF_lon are replicated in a similar manner, you can avoid that too, but then we need to talk further.
F=griddedInterpolant({lats,lons},mask50);
m50m=repmat(F(REF_lat,REF_lon),1,1,365);
for day = 1:size(ssh_int,1);
mask(:,:,day) = mask50;
ma = permute(mask,[3 1 2]);
end
I'm not sure what the rest of the operations in your for-loop are trying to accomplish, but it looks suspicious. It seems crazy to be permuting a complete 3D array in every iteration of the loop.
Best Answer