How to interpolate a set of points in 3D using Matlab (or Excel)

Dean Kayton picture Dean Kayton · Jan 24, 2013 · Viewed 7.4k times · Source

I have 19 points (x, y, z values) which can be joined up to produce a curve (very angular).

Is there a way to output 100 points (x, y, z values) which include the original 17 points after smoothing the data?

My aim is to simply make the line produced, look less angular. I don't want to depart from the original data points. I don't simply want to fit the curve, I also want a set of x, y, z values that make up as even a spread of points as possible.

If it helps to have my data, here it is...

---X--- ---Y--- ---Z---

-0.068  80.022  38.332
19.096  170.231 36.322
79.634  240.105 37.22
99.516  248.922 38.474
129.064 254.685 38.027
169.675 234.899 37.043
199.516 219.014 37.425
249.516 186.386 38.009
299.339 174.74  39.54
329.215 190.977 39.46
379.057 266.463 37.359
399.664 313.317 37.647
449.917 389.269 38.097
499.452 390.591 39.341
549.449 410.569 37.419
599.015 430.785 39.443
619.293 435.193 38.714

[UPDATE]: Here is all of my data (Eastings, Northings and Ground Elevations). I have manipulated it so that I can use it to plot a diagram and to collect the data into a long list of X, Y, Z points.

clear

XYZ=[-0.981 228.186 41.706  19.558  318.061 41.859  39.295  354.756 40.47   58.865  376.792 39.303  79.826  388.557 41.881  99.07   396.376 40.793  128.889 402.102 40.302  168.454 383.616 41.969  199.438 367.254 42.87   248.22  334.199 42.459  299.662 322.407 42.887  329.13  338.72  41.936  379.011 414.38  42.538  398.925 461.024 40.579  448.964 536.678 41.016  498.674 538.02  42.433  549.046 558.505 42.987  599.089 578.825 41.388  619.513 583.596 41.116
     -0.459 168.609 39.534  18.72   258.139 37.039  39.19   294.992 36.651  59.44   316.886 38.745  78.96   328.97  37.646  98.491  336.517 37.363  128.616 342.212 39.449  169.277 323.234 38.724  199.75  307.82  39.494  248.486 273.63  37.803  298.848 262.947 38.076  328.525 279.219 38.518  379.188 354.13  37.9    399.106 401.214 39.985  449.016 476.406 37.01   498.736 478.979 38.417  548.892 498.121 38.377  598.835 518.866 39.27   619.431 522.964 38.652
     -0.315 148.334 39.125  19.282  238.135 38.831  38.929  275.114 38.766  59.107  296.971 36.86   79.658  308.222 37.573  98.877  317.103 39.28   129.343 322.55  39.346  168.458 302.85  37.183  199.447 287.361 39.494  248.515 254.097 37.082  299.258 242.268 38.203  328.867 258.877 38.243  378.966 334.294 37.886  398.553 380.9   39.661  449.357 457.216 37.151  499.188 458.425 39.993  548.447 478.633 39.044  599.289 498.829 38.229  619.362 502.861 38.28
     -0.77  128.802 40.307  18.84   218.299 37.872  39.619  255.281 38.875  59.158  277.506 38.86   79.475  289.08  38.727  98.903  297.194 39.254  128.637 303.058 40.618  169.416 283.797 39.046  199.218 268.002 39.514  248.851 234.409 38.522  299.708 222.995 38.598  328.737 239.682 39.346  379.221 315.113 39.674  398.469 361.458 40.085  449.262 437.299 38.544  499.091 438.992 39.367  548.492 458.732 40.047  599.105 479.647 39.072  619.42  483.704 40.14
     -0.582 126.998 42.05   19.007  217.113 42.128  39.658  252.392 42.117  58.79   275.466 42.097  78.995  286.233 42.1    98.972  295.658 42.09   129.273 301.556 42.12   169.316 281.063 42.049  199.634 265.439 42.085  248.752 232.621 42.08   299.1   220.782 42.143  328.877 237.643 42.145  379.427 312.91  42.095  398.721 360 42.106      449.135 435.791 42.183  499.252 437.276 42.118  548.493 457.293 42.113  599.462 477.004 42.119  619.612 482.107 42.129
     -0.346 123.16  41.94   19.179  213.589 41.992  39.444  250.331 41.987  59.072  271.995 42.065  79.307  283.649 42.022  99.006  292.466 42.056  128.633 297.74  41.918  169.34  278.56  42.011  199.026 262.206 41.932  248.941 229.711 42.027  299.509 217.911 42.066  328.821 234.132 41.946  379.845 310.058 42.021  398.534 356.907 42.014  448.593 432.35  42.003  499.106 433.69  41.987  548.428 454.372 41.974  599.328 474.769 42.067  618.992 478.889 41.937
     0.732  122.04  40.776  19.669  212.233 39.128  40.645  248.583 39.894  60.286  271.062 39.729  80.595  282.456 40.269  99.954  291.342 40.844  130.501 297.006 40.859  169.595 277.813 40.096  200.624 261.129 40.458  250.007 229.335 40.355  299.901 217.206 40.553  329.726 233.434 40.522  380.156 308.505 40.544  399.69  355.738 40.892  449.73  432.099 40.119  500.35  433.178 40.041  549.542 452.726 40.361  599.9   472.971 40.571  620.914 478.13  40.873
     -1.344 121.36  38.071  17.996  211.825 37.099  39.218  248.06  37.203  58.015  269.734 36.847  78.048  281.708 37.956  98.076  290.618 38.462  128.584 296.649 38.488  169.011 276.388 37.434  199.064 260.174 38.327  247.515 227.828 38.149  298.297 216.494 38      328.879 232.531 38.172  378.679 307.684 37.624  398.234 355.057 38.044  448.11  430.336 37.532  498.174 432.199 37.789  547.705 451.963 37.549  599.229 472.621 38.385  618.971 476.745 38.149
     -0.025 120.11  34.797  20.25   211.177 34.062  39.791  247.155 34.197  60.031  268.877 34.045  79.895  281.005 34.402  98.319  289.127 35.76   128.885 295.177 35.434  169.826 275.718 34.468  199.41  259.111 34.855  249.34  227.082 34.555  299.862 215.112 35.461  329.614 231.681 35.356  380.185 307.267 35.34   399.585 353.472 35.311  449.785 430.221 34.802  499.27  431.338 34.628  548.82  450.964 35.164  599.091 471.717 35.328  620.312 475.724 35.55
     -0.22  119.594 33.729  19.409  209.329 32.717  38.952  245.437 33.72   59.524  268.074 33.425  79.777  279.98  33.954  98.221  288.432 34.334  129.045 294.204 34.573  169.076 274.494 33.237  198.901 258.488 33.931  248.337 225.817 33.355  298.963 214.171 34.017  329.011 230.691 34.245  379.806 305.861 34.482  399.2   353.067 34.781  448.965 429.152 33.325  498.859 429.646 34.004  549.241 449.899 33.331  599.566 469.81  33.805  619.033 475.192 34.044
     -0.225 118.011 32.993  18.767  208.144 32.997  38.816  244.302 32.999  59.56   266.523 33      79.533  278.085 32.99   98.422  286.837 32.993  129.264 292.591 32.991  168.522 272.813 33      198.936 256.937 32.993  248.787 224.365 33      299.14  212.644 32.992  328.757 228.921 32.993  379.797 304.381 32.998  399.188 351.229 32.994  449.075 427.265 32.999  498.928 428.532 32.998  548.59  448.554 32.993  599.185 468.737 32.995  619.838 473.133 32.994
     0.621  116.948 29.909  19.99   207.148 30.037  39.828  243.381 30.798  60.108  265.55  30.687  80.123  277.034 30.203  99.647  285.902 30.446  129.735 291.642 30.013  169.481 271.894 30.259  200.112 255.971 30.639  250.02  223.322 29.845  299.877 211.67  30.08   329.708 227.976 30.485  380.238 303.376 30.104  399.691 350.269 30.584  450.269 426.249 30.768  499.599 427.533 30.542  549.958 447.544 30.502  599.951 467.709 30.06   620.941 472.167 30.208
     -0.764 116.091 29.656  19.114  206.308 29.417  39.503  242.409 29.762  58.815  264.591 29.656  79.524  276.201 29.433  98.229  284.95  30.045  128.936 290.766 29.586  169.234 270.961 29.458  199.626 255.101 29.597  248.778 222.44  30.026  299.703 210.767 29.356  328.629 227.031 29.329  379.544 302.545 29.563  398.596 349.349 30.033  448.827 425.363 29.419  499.04  426.678 29.556  548.678 446.571 29.945  599.294 466.821 29.69   619.696 471.208 29.793
     -1.067 114.032 29.719  19.44   204.246 29.119  39.558  240.395 29.361  58.93   262.605 29.134  79.298  274.13  29.365  99.142  283.016 29.311  128.92  288.727 30.017  168.483 268.939 29.621  199.399 253.114 29.763  248.163 220.412 29.536  299.041 208.813 30.081  328.428 224.993 29.988  379.119 300.524 29.264  398.432 347.396 29.329  449.335 423.34  29.239  498.819 424.664 29.507  548.946 444.58  29.779  599.548 464.871 29.66   619.106 469.274 29.565
     -0.442 112.052 29.67   19.416  202.325 30.321  39.044  238.412 30.206  58.7    260.631 29.445  79.109  272.111 29.516  98.874  280.979 29.808  129.073 286.749 30.109  168.462 266.997 30.066  199.294 251.089 29.504  248.892 218.387 29.935  299.385 206.805 29.805  328.344 222.983 30.333  379.741 298.521 29.6    399.272 345.318 29.406  449.344 421.312 29.856  498.616 422.67  29.603  548.988 442.654 29.853  599.455 462.863 29.855  619.505 467.26  30.163
     0.279  111.075 31.219  19.664  201.272 31.227  40.033  237.484 31.24   60.51   259.593 31.227  80.873  271.165 31.24   99.424  279.93  31.246  129.935 285.73  31.221  169.713 265.97  31.209  199.969 250.021 31.234  250.08  217.416 31.244  300.368 205.831 31.233  329.826 222.066 31.207  380.292 297.464 31.249  399.692 344.335 31.208  450.288 420.325 31.235  500.029 421.615 31.25   549.758 441.59  31.244  599.982 461.843 31.223  620.805 466.263 31.248
     -0.196 110.635 32.995  19.493  200.514 32.992  38.713  237.169 32.999  59.287  259.517 32.999  79.892  271.021 32.993  98.751  279.466 32.996  128.785 285.668 32.999  169.139 265.219 32.996  199.347 249.546 32.998  248.81  216.85  32.995  298.841 205.432 32.999  328.21  221.91  32.995  379.636 297.352 32.999  398.784 343.398 32.991  449.428 419.375 32.997  499.043 421.018 32.991  548.969 441.046 32.994  599.524 460.831 32.994  619.193 466.092 32.995
     -0.132 109.594 34.42   20.125  199.858 32.732  39.776  236.054 33.054  60.129  257.645 33.431  80.851  269.508 34.218  99.269  278.227 33.904  130     283.99  34.048  169.914 264.152 33.073  200.719 248.544 34.04   249.707 215.652 33.406  300.225 203.878 34.126  329.592 220.167 33.769  380.754 296.156 34.421  399.397 342.405 33.861  450.468 418.693 33.948  499.96  420.455 33.265  549.437 440.39  33.953  599.864 460.69  34.351  620.874 465.104 34.09
     -0.343 108.513 34.78   19.3    198.316 33.888  38.786  234.577 34.484  59.053  257.223 33.853  79.285  268.324 35.043  98.398  277.644 34.937  128.83  283.213 35.301  169.088 263.069 35.014  198.878 247.767 35.609  248.615 214.391 35.807  299.485 202.82  35.357  328.648 219.254 35.022  379.743 294.584 34.429  398.637 342.162 35.193  449.496 418.209 35.108  499.324 419.115 34.295  548.907 439.475 34.687  598.883 458.884 34.303  619.369 463.964 34.851
     0.423  107.454 36.297  19.785  197.317 35.425  40.375  233.902 35.959  60.09   255.777 35.783  80.63   268.02  36.853  99.567  276.422 36.795  130.287 282.576 36.835  170.145 262.756 36.119  200.352 246.912 36.895  249.614 213.916 36.907  299.812 202.349 36.713  329.403 218.774 36.711  380.395 294.154 36.327  399.866 341.226 36.943  449.724 416.448 36.271  500.452 418.301 36.213  549.877 437.585 36.038  600.532 458.707 36.157  620.02  462.977 36.445
     -0.088 106.391 40.184  19.793  197.12  39.075  40.586  232.691 39.109  59.812  255.447 39.332  79.952  266.173 39.494  99.221  275.594 40.444  129.757 281.51  40.035  170.036 261.36  39.122  199.869 245.174 40.197  250.045 212.441 39.611  300.362 201.267 39.588  329.451 217.04  40.17   380.741 292.932 40.168  399.997 339.678 40.689  450.209 415.475 39.322  499.581 417.128 39.793  549.785 437.368 39.621  599.735 457.43  40.383  620.764 461.816 40.233
     -0.578 103.781 42.003  18.861  194.176 42.045  39.371  229.481 42.045  58.832  252.026 42.095  79.04   263.57  42.06   98.512  271.997 42.08   129.028 278.247 42.052  169.367 258.679 42.04   199.296 242.657 42.005  248.473 210.079 42.02   299.209 198.553 42.079  328.911 214.091 42.047  378.934 290.029 42.014  398.408 337.125 42.037  448.973 412.977 42.099  499.168 413.779 42.082  548.53  433.779 42.039  599.266 454.462 42.098  619.302 458.232 42.098
     0.108  101.868 41.937  20.502  191.246 41.969  39.879  228.172 41.928  60.084  250.124 41.99   80.344  261.778 41.968  99.165  270.769 41.961  129.622 276.502 41.91   170.288 256.048 41.977  200.321 240.195 41.922  249.569 208.29  41.938  300.539 195.873 41.995  329.966 212.825 41.937  380.491 288.359 41.984  399.837 334.911 41.998  450.207 410.929 41.96   500.101 411.893 41.925  549.602 431.696 41.936  599.93  452.41  41.976  620.817 456.93  41.909
     -0.156 100.022 40.698  19.591  190.231 39.108  39.68   226.389 39.847  59.626  248.557 39.725  79.928  260.105 40.23   99.158  268.922 40.825  129.536 274.685 40.797  169.45  254.899 40.03   199.86  239.014 40.391  249.085 206.386 40.338  299.722 194.74  40.504  329.176 210.977 40.424  379.918 286.463 40.51   399.298 333.317 40.82   449.58  409.269 40.059  499.539 410.591 40.02   549.289 430.569 40.294  599.64  450.785 40.472  619.954 455.193 40.809
     -0.068 80.022  38.332  19.096  170.231 36.322  NaN     NaN     NaN     NaN     NaN     NaN     79.634  240.105 37.22   99.516  248.922 38.474  129.064 254.685 38.027  169.675 234.899 37.043  199.516 219.014 37.425  249.516 186.386 38.009  299.339 174.74  39.54   329.215 190.977 39.46   379.057 266.463 37.359  399.664 313.317 37.647  449.917 389.269 38.097  499.452 390.591 39.341  549.449 410.569 37.419  599.015 430.785 39.443  619.293 435.193 38.714
     -0.879 60.235  38.12   19.794  150.69  37.633  NaN     NaN     NaN     NaN     NaN     NaN     79.676  220.614 38.967  99.268  229.482 38.436  129.881 235.374 38.61   169.79  215.494 39.999  199.482 199.431 39.078  249.724 166.529 38.679  299.764 155.498 39.377  329.036 171.037 38.953  379.673 247.306 38.455  399.205 293.707 38.795  449.438 369.592 39.867  499.811 371.176 38.781  549.221 390.944 39.002  599.331 411.525 39.837  619.223 415.971 38.836
     -0.056 10.391  42.313  19.883  100.806 39.381  NaN     NaN     NaN     NaN     NaN     NaN     79.393  170.931 40.647  99.816  179.896 40.183  129.278 185.549 40.86   169.362 165.621 40.561  199.201 149.789 40.356  249.526 117.283 40.668  299.544 104.913 41.298  329.4   121.509 41.644  379.295 197.056 40.755  399.8   244.073 41.207  449.299 319.634 40.484  499.926 320.765 41.034  549.511 341.235 40.568  599.448 361.452 40.63   619.025 366.018 40.615];

clf
hold all
%Y-DIRECTION
for k=1:19
    X_vert=[XYZ(:,3*k-2)];
    Y_vert=[XYZ(:,3*k-1)];
    Z_vert=[XYZ(:,3*k)];
    plot3(X_vert, Y_vert, Z_vert);
    pause(0.01)
end
%X-DIRECTION
for k=1:27
    X_horz=[XYZ(k,1:3:57)];
    Y_horz=[XYZ(k,2:3:57)];
    Z_horz=[XYZ(k,3:3:57)];
    plot3(X_horz, Y_horz, Z_horz);
    pause(0.01)
end
axis equal
%REARRANGED INTO 3-COLUMN LIST
X=[];
Y=[];
Z=[];
for k=1:19
    X=[X;XYZ(:,3*k-2)];
    Y=[Y;XYZ(:,3*k-1)];
    Z=[Z;XYZ(:,3*k)];
end
XYZ=[X Y Z];

Answer

bla picture bla · Jan 24, 2013

So if I understand you correctly you just want to interpolate in 3D. A good solution from the file exchange can be interparc. It allows you to do linear or spline interpolation for a general curve in n-dimensions.