How can I achieve interpolation over the entire Cartesian space, without being limited by the convex hull of the data points, with TriScatterInterp (or griddata)?
1 view (last 30 days)
Show older comments
LORENZO DOPPIU
on 10 Aug 2023
Commented: LORENZO DOPPIU
on 13 Aug 2023
I have written these lines of code and it is prefectly working. The problem is that I would like the interpolation to take place over the entire cartesian space, instead of within the data-points delimited polygon only.
I would like to achieve a full-colored interpolated image, instead of a colored shape immersed in the white surrounding. How can I achieve that?
Thank you all for your help!
% Data points
data_points = [1,1,3;1.02,1.9,3.1; 4,2,3.5; 4,4,2; 5,4.5,3];
% Define the grid within which you want to interpolate
[x_grid, y_grid] = meshgrid(linspace(0, 10, 100), linspace(0, 10, 100));
% Extract x, y, and values from data points
x = data_points(:, 1);
y = data_points(:, 2);
values = data_points(:, 3);
% Create a TriScatteredInterp object for interpolation
F = TriScatteredInterp(x, y, values, 'linear');
% Evaluate the interpolation on the grid
interpolated_values = F(x_grid, y_grid);
% Plot the interpolated result
contourf(x_grid, y_grid, interpolated_values, 50);
colorbar;
hold on;
scatter(x, y, 'r', 'filled', 'DisplayName', 'Data Points');
xlim([0, 10]);
ylim([0, 10]);
xlabel('X');
ylabel('Y');
title('Interpolated Data');
legend('Location', 'Best');
hold off;
0 Comments
Accepted Answer
Walter Roberson
on 10 Aug 2023
Edited: Walter Roberson
on 10 Aug 2023
These days it is recommended that you switch to griddedInterpolant or scatteredInterpolant making sure to tell them to extrapolate.
More Answers (0)
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!