# Using griddata with two points

6 views (last 30 days)

Show older comments

Christian Mathiesen
on 29 Oct 2021

Answered: Rishabh Singh
on 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 Comments

Rishabh Singh
on 1 Nov 2021

### Accepted Answer

Rishabh Singh
on 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 Comments

### More Answers (0)

### See Also

### Categories

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!