Using griddata with two points
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Christian Mathiesen
le 29 Oct 2021
Réponse apportée : Rishabh Singh
le 5 Nov 2021
I have three datasets, containing x, y and z data. The datasets contains two, seven and fourteen points respectively. My goal is to visualize the increasing interpolation quality with increasing points. I have used griddata, but I am unable to create an interpolation with the dataset only containing two points. I get the error "Warning: The underlying triangulation is empty - the points may be collinear". I have searched around for a solution, and as far as I understand, griddata is unable to work with only two points. It is working fine with the other two datasets. Is there an alternative?
Thank you in advance!
TwoPoints = load('002536_2_punkter.txt');
SevenPoints = load('002536_7_punkter.txt');
FourteenPoints = load('002536_14_punkter.txt');
two_x = TwoPoints(:,1);
two_y = TwoPoints(:,2);
two_d = TwoPoints(:,3);
seven_x = SevenPoints(:,1);
seven_y = SevenPoints(:,2);
seven_d = SevenPoints(:,3);
fourteen_x = FourteenPoints(:,1);
fourteen_y = FourteenPoints(:,2);
fourteen_d = FourteenPoints(:,3);
v = 2000; %p-wave velocity of sediment
%Converting d-values from seconds to meter.
two_d = two_d .* v;
seven_d = seven_d .* v;
fourteen_d = fourteen_d .* v;
dx = 5;
x_ax=min(fourteen_x):dx:max(fourteen_x);
y_ax=min(fourteen_y):dx:max(fourteen_y);
[xx,yy]=meshgrid(x_ax,y_ax);
%Creating figures
figure();
Z_two = griddata(two_x,two_y,two_d,xx,yy,'cubic'); %This does not work
imagesc(x_ax,y_ax,Z_two)
hold on
plot(two_x,two_y,'k.','MarkerSize',22);
scatter(two_x,two_y,8,two_d,'filled');axis image
hold off
colorbar
caxis([20 35])
set(gca,'YDir','normal')
figure();
Z_seven = griddata(seven_x,seven_y,seven_d,xx,yy,'cubic');
imagesc(x_ax,y_ax,Z_seven)
hold on
plot(seven_x,seven_y,'k.','MarkerSize',22);
scatter(seven_x,seven_y,8,seven_d,'filled');axis image
hold off
colorbar
caxis([25 50])
set(gca,'YDir','normal')
figure();
Z_fourteen = griddata(fourteen_x,fourteen_y,fourteen_d,xx,yy,'cubic');
imagesc(x_ax,y_ax,Z_fourteen)
hold on
plot(fourteen_x,fourteen_y,'k.','MarkerSize',22);
scatter(fourteen_x,fourteen_y,8,fourteen_d,'filled');axis image
hold off
colorbar
caxis([25 50])
set(gca,'YDir','normal')
2 commentaires
Rishabh Singh
le 1 Nov 2021
It is not possible to create a mesh/surface from two points, you atleast need 3 points to triagulate a surface. So "griddata" will not be suitable for you. Can you explain the meaning " visualize the increasing interpolation quality ", so any alternate solution can be suggested.
Réponse acceptée
Rishabh Singh
le 5 Nov 2021
As you wish to compare the results of interpolation I would suggest you to start from atleat 3 data points, if that is possible. As two data points do not carry much information so as to perform interpolation of any sort.
Hope it helps.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Interpolating Gridded Data dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!