Once with assistance of Stephon, i prepared this code which was running according to my all requirements expect than scatteredInterpolant. Please also check it may modify it if you can.
metC = {'linear','cubic','next','pchip','previous','spline','v5cubic','nearest'};
% Read the file data:
S = dir('Output_*.txt');
N = sort({S.name});
nmf = numel(N);
nmr = size(load(N{1},'-ascii'),1);
mat = zeros(nmr,3,nmf);
for k = 1:nmf
mat(:,:,k) = load(N{k},'-ascii');
end
tmp = 0==diff(mat(:,1:2,:),1,3);
assert(all(tmp(:)),'First columns do not match')
% Rearrange:
[VC,NA,IC] = unique(mat(:,1,1));
[VR,NA,IR] = unique(mat(:,2,1));
out = reshape(mat(:,3,:),numel(VR),numel(VC),nmf);
% Detect -9999:
idx = out<(-9998);
% Interpolate:
vec = 1:nmf;% 24 times
for m = 1:numel(metC)% the length of techniques
metS = metC{m} % the method
for r = 1:numel(VR)% 19 times
for c = 1:numel(VC)% 17 times
idy = squeeze(idx(r,c,:)).'; % removing dimension 1
if any(idy)
Xold = vec(~idy);
Yold = squeeze(out(r,c,~idy)).';
Xnew = vec(idy);
out(r,c,idy) = interp1(Xold,Yold,Xnew,metS,'extrap');
end
end
end
% Write to file:
pressures = [1000, 925, 850, 700, 600, 500, 400, 300, 250, 200, 150, 100, 70, 50, 30, 20, 15, 10, 7, 5, 3, 2, 1.5, 1] ;
for k = 1:nmf
fprintf('Export Interpolation. %d -> p=%.1f hpa.\n', k-1, pressures(k) );
str = sprintf('Interpolated_%s_%d.txt', metS, k-1);
fid = fopen(str,'wt');
fprintf(fid,' \t \t \n');
tmp = out(:,:,k);
fprintf(fid,'%.3f\t%.3f\t%.3f\n',[mat(:,1:2),tmp(:)].');
fclose(fid);
end
end