Error using scatteredInterpolant on missing data

12 次查看(过去 30 天)
Hello everyone,
I would like to use function scatteredInterpolant or interp1 to compare results with fillmissing function and inpaint_nans on the leading or trailing missing values (NaN)/ peak at the edge as attached file.
However, it has this error when I tried to input the data. I tried to read some instruction on MATLAB, but my data, it does not have any functions of x and y for z. Could anyone please help me figure out the reason to input the data properly?.
Thank you very much!
T = readtable ('data.csv')
T = 48×78 table
Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 Var9 Var10 Var11 Var12 Var13 Var14 Var15 Var16 Var17 Var18 Var19 Var20 Var21 Var22 Var23 Var24 Var25 Var26 Var27 Var28 Var29 Var30 Var31 Var32 Var33 Var34 Var35 Var36 Var37 Var38 Var39 Var40 Var41 Var42 Var43 Var44 Var45 Var46 Var47 Var48 Var49 Var50 Var51 Var52 Var53 Var54 Var55 Var56 Var57 Var58 Var59 Var60 Var61 Var62 Var63 Var64 Var65 Var66 Var67 Var68 Var69 Var70 Var71 Var72 Var73 Var74 Var75 Var76 Var77 Var78 ____ ____ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ NaN 220 225 230 235 240 245 250 255 260 265 270 275 280 285 290 295 300 305 310 315 320 325 330 335 340 345 350 355 360 365 370 375 380 385 390 395 400 405 410 415 420 425 430 435 440 445 450 455 460 465 470 475 480 485 490 495 500 505 510 515 520 525 530 535 540 545 550 555 560 565 570 575 580 585 590 595 600 220 0 2.5291 4.9719 7.3376 9.6358 11.876 14.067 16.142 18.555 19.379 22.763 27.167 33.454 39.96 49.029 58.273 70.904 80.704 92.344 111.66 140.53 176.26 222.44 284.14 357.17 492.42 876.46 NaN NaN NaN NaN NaN NaN NaN NaN 860.63 842.97 839.29 857.11 856.6 851.1 833.65 815.51 795.43 775.14 756.35 740.79 730.19 726.27 738.09 713.27 652.12 574.65 500.84 450.67 426.03 375.58 349.23 323.76 296.29 272.8 255 227.99 204.68 186.53 170.45 158.08 144.13 134.67 117.42 106.98 94.146 79.954 70.347 62.752 53.511 47.649 225 0 2.3454 4.5736 6.6946 8.7186 10.656 12.516 14.309 15.938 16.093 18.621 23.33 28.919 34.137 46.978 56.433 63.981 75.15 86.962 104.25 132.6 176.47 213.42 268.34 338.89 449.63 758.19 NaN NaN NaN NaN NaN NaN NaN 928.86 816.35 807.32 798.92 832.64 831.66 821.93 801.63 777.59 762.99 750.44 740.69 731.62 721.11 707.05 687.31 659.79 549.98 501.4 458.02 416.97 379.09 345.25 317.29 292.13 269.32 240.14 220.56 198.53 179.09 166.2 149.51 135.39 122.35 111.93 102.98 88.039 77.718 65.74 57.572 51.801 46.011 42.86 230 0 0 3.9109 5.7736 7.5808 9.337 11.047 12.716 14.347 15.947 17.441 19.855 21.406 28.783 37.509 49.468 58.689 68.949 79.181 91.367 118.75 153.91 193.5 237.6 300.07 391.26 632.38 NaN NaN NaN NaN NaN NaN NaN 860.19 773.2 782.34 784.78 804.8 808.58 819.79 784.53 771.31 748.79 735.4 709.82 680.97 650.52 618.53 585.04 550.09 513.73 476.01 433.86 394.32 359.2 326 295.6 268.87 247.35 218.56 200.03 180.53 160.23 142.44 129.75 116.7 105.83 97.123 86.956 74.889 65.953 54.317 51.251 43.055 38.219 34.51 235 0 0 0 3.1716 4.5806 6.1327 7.8085 9.5882 11.452 13.381 15.355 17.75 19.162 23.332 29.925 37.485 46.616 56.52 67.022 82.487 104.15 131.02 164.82 208.68 266.96 349.06 545.05 778.52 NaN NaN NaN NaN NaN 955.73 817.79 764.31 771.01 785.21 794.13 807.57 805.07 783.83 770.46 745.19 732.3 714.69 718.82 663.1 618.79 579.52 543.52 509.06 474.39 437.74 397.37 351 314.75 285.32 258.57 233.93 210.85 188.75 168.68 150.78 133.83 117.69 109.39 96.963 85.78 76.735 65.421 57.772 48.761 41.9 38.387 32.356 30.457 240 0 0 0 0 5.6491 7.1198 8.6101 10.118 11.641 13.178 14.727 16.285 17.898 21.401 26.73 33.952 42.49 52.109 61.606 76.14 98.263 121.18 157.81 193.05 242.9 322.26 484.51 676.64 NaN NaN NaN NaN 985.89 877.68 775.7 746.03 751.08 762.72 782.31 784.97 791.79 765.72 758.44 736.49 724.08 698.22 692.23 650.91 620.06 601.13 571.9 533.69 489.46 442.18 394.79 350.27 311.56 279.78 248.99 227.41 205.74 183.97 163.05 143.96 127.65 113.72 102.26 91.154 78.479 70.941 59.505 52.924 43.815 38.886 35.072 30.524 26.523 245 0 0 0 0 0 10.141 11.8 13.348 14.789 16.128 17.369 18.519 19.581 20.424 24.843 32.37 40.192 47.656 59.313 76.853 99.512 127.69 160.8 198.44 244.47 307.94 445.2 603.33 795.54 968 NaN NaN 878.93 799.51 710.65 699.07 714.35 721.21 736.32 747.03 744.09 736.3 725.43 709.28 695.49 681.77 667.95 628.15 599.09 582.3 547.76 484.39 440.01 401.38 367.16 336.04 306.69 277.78 247.99 218.93 193.69 175.84 158.53 141.46 125.06 109.77 96.23 85.268 76.698 66.312 55.993 48.141 40.773 35.997 29.842 26.896 24.102 250 0 0 0 0 0 0 5.7471 7.6197 9.6875 11.926 14.309 16.814 19.414 22.085 26.094 32.257 40.324 49.966 63.624 79.413 108.35 140.88 173.12 215.2 259.57 317.13 427.94 563.26 701.74 838.27 905.88 842.11 767.2 706.82 645.53 635.28 649.79 664.95 682.03 687.74 694.07 685.87 677.66 664.54 660.16 639.59 634.4 594.13 567.51 547.43 519.32 456.69 421.65 386.05 355.43 326.8 299.7 273.68 248.26 222.98 197.38 172.05 148.93 130.57 115.81 103.58 92.528 82.083 71.673 61.369 52.675 43.936 37.22 31.482 28.787 25.601 22.098 255 0 0 0 0 0 0 0 13.147 15.399 17.717 20.09 22.511 24.83 27.201 30.068 33.875 40.921 50.95 63.297 86.155 121.46 159.66 200.13 243.3 288.83 345.43 432.18 537.99 644.45 742.26 788.51 735.9 675.18 632.05 586.72 582.59 589.9 602.46 625.03 638.41 642.82 641.27 635.56 625.74 615.81 603.58 595.49 564.08 537.1 517.58 485.15 433.37 396.29 364.84 333.44 301.3 275.93 253.24 232.45 212.75 193.35 173.43 152.22 129.54 110.37 98.219 86.191 76.037 66.75 58.023 49.548 41.512 35.523 30.885 26.593 23.008 20.573 260 0 0 0 0 0 0 0 0 12.09 14.812 17.681 20.662 23.718 27.311 31.929 37.572 44.241 54.036 69.094 93.649 141.22 185.95 228.84 281.06 334.29 378.58 455.19 536.27 617.95 689.11 710.84 676.11 630.61 587.88 560.13 555.17 557.89 566.54 586.38 593.9 600.28 594.72 587.41 581.56 576.95 562.71 549.64 522.13 499.21 480.67 452.48 402.61 371.29 340.44 305.48 279.24 250.43 227.03 208.88 193.24 179.1 165.45 151.3 135.64 117.45 93.956 81.441 70.85 62.039 54.505 47.456 40.89 34.804 29.195 24.381 21.413 18.64 265 0 0 0 0 0 0 0 0 0 15.374 18.592 22.027 25.655 29.454 34.39 41.311 50.016 60.304 75.71 108.89 163.97 215.79 270.21 328.43 381.08 424.46 489.76 555.5 619.44 662.87 677.98 647.35 617.62 584.48 553.01 544.97 545.49 548.1 562.54 567.48 569.99 565.8 557.58 550.66 542.62 528.08 514.36 484.6 460.56 444.32 418.49 373.3 342.77 310.63 282.57 256.62 229.34 205.06 184.86 168.5 156.1 145.82 136.68 127.72 117.97 106.46 92.228 70.22 58.324 49.899 40.844 35.388 31.099 27.255 23.941 21.245 19.315 270 0 0 0 0 0 0 0 0 0 0 22.194 26.438 30.966 35.759 40.795 47 55.826 68.049 84.44 120.32 188.05 246.86 305.15 368.98 424.16 468.2 529.19 588.33 638.95 676.56 683.98 656.79 633.06 598.83 568.67 556 553.15 556.65 563.52 568.49 562.4 555.19 546.31 534.13 521.44 506.68 491.3 464.62 439.5 416.84 393.26 351.43 321.65 291.4 265.02 238.03 212.13 191 170.85 154.38 137.63 125.47 116.55 109.39 103.14 96.975 90.041 81.502 70.516 51.168 39.531 33.596 29.356 25.667 22.962 20.72 19.255 275 0 0 0 0 0 0 0 0 0 0 0 29.345 34.854 40.824 47.253 54.136 64.313 81.058 105.03 136.87 207.97 275.51 340.03 404.38 467.57 510.47 567.36 616.7 660.51 687.88 700.3 675.69 662.33 632.65 603 590.46 583.15 581.42 584.94 588.29 581.63 565.11 555.86 539.92 521.63 503.61 486.3 456.31 430.26 407.14 382.57 340.47 309.47 282.72 256.7 229.41 205.72 183.46 163.6 147.16 129.79 114.97 102.02 93.206 86.973 82.165 78.075 74 69.235 63.074 54.814 37.64 29.709 25.357 22.391 19.823 19.071 280 0 0 0 0 0 0 0 0 0 0 0 0 38.313 44.39 50.817 57.571 64.634 77.24 109.76 163.79 228.6 293.45 360.77 431.26 492.5 539.37 595.26 652.41 696.22 722.16 729.6 712.24 696.71 672.62 648.27 629.15 621.33 621.41 623.67 619.72 608.63 590.71 577.85 558.83 542.86 517.1 496.14 465 434.97 406.96 380.21 339.34 308.75 279.95 252.31 227.19 200.86 178.01 159.88 141.35 125.63 111.26 98.806 88.658 78.356 71.912 67.631 64.527 62.003 59.459 56.299 51.923 45.734 28.751 22.519 19.661 17.736 285 0 0 0 0 0 0 0 0 0 0 0 0 0 37.127 43.677 50.777 58.43 66.64 86.215 131.37 202.21 284.08 362.35 435.72 497.17 547.7 603.16 655.12 697.84 725.92 740.72 736.13 732.92 714.36 694.89 680.33 669.25 666.62 669.66 662.25 652.66 633.38 613.54 591.86 569.24 542.29 519.53 483.45 448.44 418.63 388.3 345.38 313.72 282.8 252.29 228.26 201.18 178.85 160.01 141.91 124.93 111.03 96.574 87.272 76.31 67.68 59.457 55.295 52.367 50.217 48.425 46.57 44.229 40.983 36.41 23.103 17.934 290 0 0 0 0 0 0 0 0 0 0 0 0 0 0 36.699 44.272 52.738 62.141 72.523 118.74 182.71 259.56 339.64 413.31 476.88 527.6 585.93 644.91 694.51 731.39 747.82 760.9 766.53 753.46 739.73 727.94 720.07 720.82 723.52 713.97 701.85 683.92 660.94 636.53 611.03 579.21 547.99 510.45 470.17 439.36 405.67 359.38 322.97 290.68 259.3 231.35 203.94 180.72 159.97 142.58 125.2 111.54 96.505 85.595 75.318 67.29 58.558 50.707 44.885 40.93 38.996 37.287 35.83 34.65 33.774 33.229 33.042
data = table2array(T) ;
x = data(1,:) ; x(1) = [] ;
y = data(:,1) ; y(1) = [] ;
z = data(2:end,2:end) ;
F = scatteredInterpolant(x,y,z)
Error using scatteredInterpolant
The input points must be specified in column-vector format.
Error using scatteredInterpolant
The input points must be specified in column-vector format.

采纳的回答

Cris LaPierre
Cris LaPierre 2022-11-22
When using the syntax F = scatteredInterpolant(x,y,v), your inputs must all be vectors. That means v=z(:), and that x and y are the same length as v. Try something like this.
T = readtable ('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1203033/data.csv');
data = table2array(T) ;
x = data(1,:) ; x(1) = [] ;
y = data(:,1) ; y(1) = [] ;
z = data(2:end,2:end) ;
[X,Y] = meshgrid(x,y);
F = scatteredInterpolant(X(:),Y(:),z(:))
F =
scatteredInterpolant with properties: Points: [3619×2 double] Values: [3619×1 double] Method: 'linear' ExtrapolationMethod: 'linear'
% visualize the result
[xq,yq] = meshgrid(linspace(400,450),linspace(150,200));
vq = F(xq,yq);
plot3(X(:),Y(:),z(:),'b.',xq,yq,vq,'r.')
  1 个评论
Gem
Gem 2022-11-23
Thank you very much for your kind explanation, now I truly understand the data input and differences of results among functions to interpolate/extrapolate query points or missing data.
Best regards,
Nguyen Ngoc

请先登录,再进行评论。

更多回答(1 个)

Kai
Kai 2022-11-22
Hi Ngoc, so for the scatteredInterpolant function, it's goal is to get the interpolant based on given x y z coordinates and the corresponding values on these coordinates. Based on your csv file, I am assuming you are trying to interpolate 2D data. In this case will be F = scatteredInterpolant (x,y,v), which the function itself is trying to get the F in v = F(x,y). After F is calculated, you can bring in the sampled point coordinate (x_s,y_s) in to F(x_s,y_s) to get the interpolate values.
As for the column-vector error, the scatteredInterpolant’s input data must be in sizes of m x 1, you can use transpose or reshape to change it into column-vector format to solve the error.
Also based on your code, you only extracted the values of x and y, but didn't match them into coordinate (x,y), and that is why the size of x and y arrays are different. I will recommend checking this example in the link and specifically the size differences of the sample array used in it: 2D interpolant sample
  1 个评论
Gem
Gem 2022-11-23
Dear Kai,
Thank you very much for your understandable comment.
I can learn a lot from your explanation, combined with Cris LaPierre 's comment. I can solve my problem.
Best regards,
Nguyen Ngoc

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Time Series Events 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by