How to do 2D/3D bivariate Interpolation of Non-gridded data?
7 views (last 30 days)
Show older comments
NISHANT SURESHBHAI TEJANI
on 22 Oct 2022
Commented: Image Analyst
on 23 Oct 2022
If I have following data set (given as <Data_Set.csv> and as 'Snapshot'). From which, I want to calculate interpolation of specific data point(s). What function is available? As following data is Non-gridded (non-uniform spaced) and not of same dimensions (means dimension of X-variable (4.5 to 8) <dimension-8> and dimension of Y-variable (1 to 300) <dimension-32>. Suppose I want the value from interpolation as query point of Xq=5.75 and Yq=25 or at any points inside the boundary of data set.

0 Comments
Accepted Answer
Image Analyst
on 23 Oct 2022
OK, maybe my demo was too complicated for you to figure out how to adapt it. But it's actually quite simple. Here it is:
data = readmatrix('Data_Set.csv')
yVector = data(3:end, 1);
xVector = data(1, 3:end);
values = data(3:end, 3:end);
[x, y] = meshgrid(xVector, yVector);
%================================ MAIN PART RIGHT HERE ==============================================
% Create the scattered interpolant. x, y, and gray levels must be column vectors so use (:) to make them column vectors.
% And grayLevels must be double or else an error gets thrown.
F = scatteredInterpolant(x(:), y(:), double(values(:)))
% The above line creates an interpolant that fits a surface of the form v = F(x,y).
% Vectors x and y specify the (x,y) coordinates of the sample points.
% v is a vector that contains the sample values associated with the points (x,y).
% Find the value at a query location.
Xq=5.75
Yq=25
z = F(Xq, Yq)
And if you look at your original data, the query point would be between index 3 and 4 in x and index 15 and 16 in y. The value of 28.1526 falls right in the middle of those 4 numbers in that square, so it seems like it's doing the interpolation correctly.
2 Comments
Image Analyst
on 23 Oct 2022
Yes but interp2 uses linear interpolation. Since your data maybe nonlinear I think scatteredInterpolant would be more accurate.
data = readmatrix('Data_Set.csv')
yVector = data(3:end, 1);
xVector = data(1, 3:end);
values = data(3:end, 3:end);
imshow(values, []);
[x, y] = meshgrid(xVector, yVector);
%================================ MAIN PART RIGHT HERE ==============================================
% Create the scattered interpolant. x, y, and gray levels must be column vectors so use (:) to make them column vectors.
% And grayLevels must be double or else an error gets thrown.
F = scatteredInterpolant(x(:), y(:), double(values(:)))
% The above line creates an interpolant that fits a surface of the form v = F(x,y).
% Vectors x and y specify the (x,y) coordinates of the sample points.
% v is a vector that contains the sample values associated with the points (x,y).
% Find the value at a query location.
Xq=5.75
Yq=25
z = F(Xq, Yq)
More Answers (1)
See Also
Categories
Find more on Interpolation 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!