0
votes

I want to basically increase my data points when I want to plot a 3d surface of my x,y coordinates and their corresponding function value z(x,y). The problem is that my coordinates do not increase monotonically so I cannot use 2d interpolation in Matlab.

A typical x,y,z combination for a few first rows might look like:

15  15  184700.882736683
15  30  215486.921407234
15  45  205691.389050234
15  60  215486.897031495
15  75  209662.528668203
15  90  215486.908134438
15  105 211342.684211922
15  120 215486.920131923
15  135 212270.488286479
15  150 215486.917843900
30  30  275146.369280109
30  45  262639.083693416
30  60  275146.334615114
30  75  267709.604291106
30  90  275146.361678640
30  105 269854.818605481
30  120 275146.331709932
30  135 271039.490475350
30  150 275146.317264820
30  15  235837.965849192

Actually I can plot scatter plot of them, or using meshgrid plot a 3d surface out of them, but since my data values are few and I know that there is no jump of values between any of them, I just wanted to increase number of data points by interpolation and make my 3d surface look finer not too coarse.

I have already read 1, 2, 3, and 4, but non of them specifically address to a solution to my issue, since my case is a 3d one.

Please do not mark my question as duplicate and copy; by just googling the title. Thanks.

1
You have z as a function of x and y. We would typically call that 2D interpolation. What is wrong with those solutions you've linked to? - Suever
actually if you wanna try interpolation 2D you will get error that your data is not monotonically increasing, and since I have z=f(x,y) I do not know how to fix this monotonic issue that has come up. See the x is monotonic, but y not, and z is function value which obviously can vary non-monotonically. - Soyol
All of the threads you have linked deal with non-monotonic data. - Suever
@Suever But either do not explicitly give a solution, or are talking about 2d problem y=f(x), and I could not get a solution to my problem out of them. - Soyol

1 Answers

1
votes

Because your data is scattered, you will need to use either griddata or scatteredInterpolant to interpolate z for a given x and y.

Here is a brief example using griddata.

% Sample at 1000 evenly spaced points over the x / y plane.
[xq, yq] = meshgrid(linspace(min(x), max(x), 1000), ...
                    linspace(min(y), max(y), 1000));

zq = griddata(x, y, z, xq, yq);

surf(xq, yq, zq)

% Plot the original points as reference
hold on
plot3(x, y, z, 'o')