Interpolating a table with missing values
Show older comments
My colleague took experimental velocity data of flow through a rectangular duct in the vertical, horizontal, and a diagonal direction. The velocity data can be seen in the attached excel picture. I need to interpolate this table, so that I can use the data to come up with one function with two inputs (x and y). I'm not too experienced with MatLAB, but I think the scatteredinterpolant function can achieve that. How would I go about interpolating the data since it is nonlinear?
Answers (2)
dpb
on 21 Jun 2016
A better experiment design could have been thought out, but...
xx=[0:0.0625:0.625 0.65];
yy=[xx(2:end) 0.675];
x=[zeros(1,12) xx xx(2:end)].';
y=[yy zeros(1,12) yy(2:end)].';
vq=griddata(x,y,v,xq,yq,'cubic');
v=[1 0.997 0.975 0.964 0.9365 0.912 0.866 0.791 0.688 0.427 0.0799 0 0.991 0.987 0.974 0.950 0.912 0.854 0.768 0.646 0.476 0.24 0.123 0 0.990 0.982 0.971 0.954 0.928 0.886 0.816 0.701 0.507 0.180 0].';
[xq,yq]=meshgrid(0:0.025:x(end),0:0.025:y(end));
vq=griddata(x,y,v,xq,yq,'cubic');
figure
plot3(x,y,v,'ok')
hold on
mesh(xq,yq,vq)
ylim([0 0.7]); xlim([0 0.7]) zlim([0 1])
grid on
xlabel('X')
ylabel('Y')
Seems to not do too badly. It appears I got the data off by one on the x=0.65 slice; there's a hump there that shouldn't be. Having to enter your data by hand, I'm not going to try to sort it out; will leave that to you...the cubic does overshoot just a tad but it's not too, too bad.
You can try the Delauney triangulation; don't know how well it'll work either with the diagonal only...
Walter Roberson
on 21 Jun 2016
Assuming that you have a variable SCFM that is NaN where the cells are empty (as would be the case if you use xlsread), and that your first column and your last row are your X and Y values:
X = SCFM(1:end-1,1);
Y = SCFM(end, 2:end);
Z = SCFM(1:end-1, 2:end);
mask = ~isnan(Z);
[r, c] = find(mask);
scattered_x = X(r);
scattered_y = Y(c);
scattered_z = Z(mask);
F = scatteredInterpolant(scattered_x, scattered_y, scattered_z);
[gX, gY] = ndgrid(X, Y);
reconstructed_Z = F(gX, gY);
surf(gX, gY, reconstructed_Z);
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!