Interpolate between two 3D lines of scattered points and delete false interpolation results

조회 수: 3 (최근 30일)
Hello,
I have two sets of Data. data1(x,y,z) and data2(x,y,z). the following code shows the data and plots it to help visualize it.
I want to interpolate between these two sets and cut away invalid interpolated data points.
the colums are the x,y and z values
data1 = [0 -71.1483620540933 152.800376024537
1 -70.8317205107499 152.648260076248
2 -70.5155832191710 152.495476065991
3 -70.1999540969100 152.342025751664
4 -69.8848370615203 152.187910891162
5 -69.5702360305551 152.033133242383
6 -69.2561549215678 151.877694563222
7 -68.9425976521115 151.721596611576
8 -68.6295681397398 151.564841145341
9 -68.3170703020057 151.407429922414
10 -68.0051080564627 151.249364700691
11 -67.6936853206640 151.090647238068
12 -67.3828060121630 150.931279292442
13 -67.0724740485130 150.771262621710
14 -66.7626933472672 150.610598983767
15 -66.4534678259790 150.449290136510
16 -66.1448014022017 150.287337837835
17 -65.8366979934885 150.124743845640
18 -65.5291615173928 149.961509917820
19 -65.2221958914679 149.797637812271
20 -64.9158050332671 149.633129286890
21 -64.6099928603436 149.467986099574
22 -64.3047632902509 149.302210008219
23 -64.0001202405421 149.135802770721
24 -63.6960676287706 148.968766144977
25 -63.3926093724897 148.801101888882
26 -63.0897493892528 148.632811760334
27 -62.7874915966130 148.463897517229
28 -62.4858399121238 148.294360917464
29 -62.1847982533384 148.124203718933
30 -61.8843705378101 147.953427679535
31 -61.5845606830922 147.782034557166
32 -61.2853726067380 147.610026109721
33 -60.9868102263009 147.437404095097
34 -60.6888774593341 147.264170271191
35 -60.3915782233910 147.090326395899
36 -60.0949164360248 146.915874227118
37 -59.7988960147888 146.740815522743
38 -59.5035208772364 146.565152040672
39 -59.2087949409208 146.388885538800
40 -58.9147221233954 146.212017775024
41 -58.6213063422135 146.034550507241
42 -58.3285515149283 145.856485493346
43 -58.0364615590932 145.677824491237
44 -57.7450403922614 145.498569258809
45 -57.4542919319863 145.318721553960
46 -57.1642200958212 145.138283134585
47 -56.8748288013194 144.957255758580
48 -56.5861219660342 144.775641183843
49 -56.2981035075189 144.593441168270
50 -56.0107773433267 144.410657469756
51 -55.7241473910111 144.227291846199
52 -55.4382175681252 144.043346055495
53 -55.1529917922225 143.858821855540
54 -54.8684739808561 143.673721004230
55 -54.5846680515795 143.488045259463
56 -54.3015779219459 143.301796379134
57 -54.0192075095086 143.114976121140
58 -53.7375607318210 142.927586243377
59 -53.4566415064362 142.739628503741
60 -53.1764537509077 142.551104660130
61 -52.8970013827887 142.362016470439
62 -52.6182883196326 142.172365692565
63 -52.3403184789926 141.982154084404
64 -52.0630957784220 141.791383403853
65 -51.7866241354742 141.600055408808
66 -51.5109074677024 141.408171857165
67 -51.2359496926600 141.215734506821
68 -50.9617547279003 141.022745115672
69 -50.6883264909765 140.829205441614
70 -50.4156688994420 140.635117242545
71 -50.1437858708500 140.440482276360
72 -49.8726813227540 140.245302300956
73 -49.6023591727070 140.049579074229
74 -49.3328233382626 139.853314354076
75 -49.0640777369740 139.656509898393
76 -48.7961262863945 139.459167465076
77 -48.5289729040773 139.261288812022
78 -48.2626215075758 139.062875697127
79 -47.9970760144434 138.863929878287
80 -47.7323403422332 138.664453113400
81 -47.4684184084987 138.464447160361
82 -47.2053141307930 138.263913777067
83 -46.9430314266696 138.062854721414
84 -46.6815742136817 137.861271751298
85 -46.4209464093826 137.659166624617
86 -46.1611519313257 137.456541099266
87 -45.9021946970641 137.253396933142
88 -45.6440786241513 137.049735884141
89 -45.3868076301406 136.845559710159
90 -45.1303856325851 136.640870169094
91 -44.8748165490383 136.435669018841
92 -44.6201042970535 136.229958017296
93 -44.3662527941839 136.023738922357
94 -44.1132659579829 135.817013491920
95 -43.8611477060037 135.609783483880
96 -43.6099019557997 135.402050656135
97 -43.3595326249242 135.193816766580
98 -43.1100436309304 134.985083573113
99 -42.8614388913717 134.775852833629
100 -42.6137223238013 134.566126306026
101 -42.3668978457727 134.355905748198
102 -42.1209693748390 134.145192918044
103 -41.8759408285536 133.933989573458
104 -41.6318161244698 133.722297472338
105 -41.3885991801410 133.510118372580
106 -41.1462939131202 133.297454032081
107 -40.9049042409611 133.084306208736
108 -40.6644340812167 132.870676660442
109 -40.4248873514404 132.656567145096
110 -40.1862679691855 132.441979420594
111 -39.9485798520054 132.226915244832
112 -39.7118269174532 132.011376375707
113 -39.4760130830824 131.795364571116
114 -39.2411422664462 131.578881588953
115 -39.0072183850980 131.361929187117
116 -38.7742453565910 131.144509123503
117 -38.5422270984785 130.926623156008
118 -38.3111675283139 130.708273042528
119 -38.0810705636504 130.489460540959
120 -37.8519401220413 130.270187409199
121 -37.6237801210400 130.050455405143
122 -37.3965944781998 129.830266286687
123 -37.1703871110739 129.609621811729
124 -36.9451619372157 129.388523738164
125 -36.7209228741785 129.166973823889
126 -36.4976738395155 128.944973826801
127 -36.2754187507801 128.722525504795
128 -36.0541615255256 128.499630615768
129 -35.8339060813053 128.276290917617
130 -35.6146563356724 128.052508168238
131 -35.3964162061804 127.828284125527
132 -35.1791896103824 127.603620547381
133 -34.9629804658319 127.378519191696
134 -34.7477926900820 127.152981816369
135 -34.5336302006861 126.927010179296
136 -34.3204969151976 126.700606038372
137 -34.1083967511696 126.473771151496
138 -33.8973336261556 126.246507276563
139 -33.6873114577088 126.018816171469
140 -33.4783341633825 125.790699594111
141 -33.2704056607301 125.562159302386
142 -33.0635298673047 125.333197054189
143 -32.8577107006598 125.103814607417
144 -32.6529520783487 124.874013719967
145 -32.4492579179246 124.643796149735
146 -32.2466321369408 124.413163654617
147 -32.0450786529507 124.182117992510
148 -31.8446013835075 123.950660921310
149 -31.6452042461646 123.718794198914
150 -31.4468911584752 123.486519583217
151 -31.2496660379927 123.253838832117
152 -31.0535328022704 123.020753703509
153 -30.8584953688615 122.787265955291
154 -30.6645576553195 122.553377345358
155 -30.4717235791975 122.319089631607
156 -30.2799970580488 122.084404571935
157 -30.0893820094269 121.849323924237
158 -29.8998823508849 121.613849446410
159 -29.7115019999763 121.377982896350
160 -29.5242448742542 121.141726031955
161 -29.3381148912721 120.905080611120
162 -29.1531159685831 120.668048391741
163 -28.9692520237406 120.430631131716
164 -28.7865269742980 120.192830588940
165 -28.6049447378085 119.954648521310
166 -28.4245092318254 119.716086686723
167 -28.2452243739020 119.477146843074
168 -28.0670940815916 119.237830748260
169 -27.8901222724476 118.998140160178
170 -27.7143128640232 118.758076836723
171 -27.5396697738717 118.517642535793
172 -27.3661969195465 118.276839015284
173 -27.1938982186008 118.035668033092
174 -27.0227775885880 117.794131347113
175 -26.8528389470613 117.552230715244
176 -26.6840862115740 117.309967895381
177 -26.5165232996796 117.067344645421
178 -26.3501541289312 116.824362723260
179 -26.1849826168821 116.581023886795
180 -26.0210126810857 116.337329893922
181 -25.8582482390953 116.093282502536
182 -25.6966932084642 115.848883470536
183 -25.5363515067457 115.604134555816
184 -25.3772270514930 115.359037516275
185 -25.2193237602595 115.113594109806
186 -25.0626455505985 114.867806094309
187 -24.9071963400634 114.621675227678
188 -24.7529800462073 114.375203267810
189 -24.6000005865836 114.128391972601
190 -24.4482618787456 113.881243099948
191 -24.2977678402466 113.633758407748
192 -24.1485223886400 113.385939653896
193 -24.0005294414789 113.137788596290
194 -23.8537929163168 112.889306992825
195 -23.7083167307069 112.640496601397
196 -23.5641048022025 112.391359179904
197 -23.4211610483570 112.141896486242
198 -23.2794893867236 111.892110278307
199 -23.1390937348556 111.642002313995];
data2 = [0 -71.9804043784130 150.229949132353
1 -71.5071436226507 150.022252001755
2 -71.0346264796777 149.814795110696
3 -70.5628588161522 149.607578417341
4 -70.0918464987326 149.400601879855
5 -69.6215953940771 149.193865456404
6 -69.1521113688439 148.987369105152
7 -68.6834002896913 148.781112784264
8 -68.2154680232776 148.575096451907
9 -67.7483204362610 148.369320066243
10 -67.2819633952999 148.163783585440
11 -66.8164027670525 147.958486967661
12 -66.3516444181770 147.753430171072
13 -65.8876942153318 147.548613153838
14 -65.4245580251750 147.344035874124
15 -64.9622417143650 147.139698290094
16 -64.5007511495600 146.935600359915
17 -64.0400921974184 146.731742041751
18 -63.5802707245983 146.528123293768
19 -63.1212925977580 146.324744074129
20 -62.6631636835558 146.121604341002
21 -62.2058898486500 145.918704052549
22 -61.7494769596988 145.716043166937
23 -61.2939308833605 145.513621642331
24 -60.8392574862935 145.311439436895
25 -60.3854626351558 145.109496508795
26 -59.9325521966058 144.907792816195
27 -59.4805320373019 144.706328317262
28 -59.0294080239021 144.505102970160
29 -58.5791860230649 144.304116733053
30 -58.1298719014484 144.103369564108
31 -57.6814715257110 143.902861421488
32 -57.2339907625109 143.702592263360
33 -56.7874354785064 143.502562047889
34 -56.3418115403558 143.302770733238
35 -55.8971248147172 143.103218277574
36 -55.4533811682490 142.903904639062
37 -55.0105864676095 142.704829775866
38 -54.5687465794569 142.505993646151
39 -54.1278673704495 142.307396208084
40 -53.6879547072456 142.109037419828
41 -53.2490144565033 141.910917239549
42 -52.8110524848811 141.713035625411
43 -52.3740746590371 141.515392535581
44 -51.9380868456297 141.317987928223
45 -51.5030949113170 141.120821761502
46 -51.0691047227574 140.923893993583
47 -50.6361221466091 140.727204582631
48 -50.2041530495304 140.530753486812
49 -49.7732032981796 140.334540664290
50 -49.3432787592150 140.138566073231
51 -48.9143852992947 139.942829671799
52 -48.4865287850771 139.747331418159
53 -48.0597150832204 139.552071270478
54 -47.6339500603829 139.357049186919
55 -47.2092395832229 139.162265125647
56 -46.7855895183987 138.967719044829
57 -46.3630057325684 138.773410902629
58 -45.9414940923904 138.579340657211
59 -45.5210604645230 138.385508266742
60 -45.1017107156244 138.191913689386
61 -44.6834507123528 137.998556883308
62 -44.2662863213666 137.805437806673
63 -43.8502234093240 137.612556417647
64 -43.4352678428833 137.419912674394
65 -43.0214254887028 137.227506535080
66 -42.6087022134406 137.035337957869
67 -42.1971038837552 136.843406900927
68 -41.7866363663046 136.651713322418
69 -41.3773055277474 136.460257180509
70 -40.9691172347416 136.269038433363
71 -40.5620773539455 136.078057039146
72 -40.1561917520175 135.887312956023
73 -39.7514662956158 135.696806142159
74 -39.3479068513986 135.506536555719
75 -38.9455192860243 135.316504154869
76 -38.5443094661510 135.126708897772
77 -38.1442832584371 134.937150742595
78 -37.7454465295409 134.747829647503
79 -37.3478051461205 134.558745570659
80 -36.9513649748343 134.369898470231
81 -36.5561318823405 134.181288304382
82 -36.1621117352975 133.992915031277
83 -35.7693104003634 133.804778609083
84 -35.3777337441965 133.616878995963
85 -34.9873876334552 133.429216150083
86 -34.5982779347976 133.241790029608
87 -34.2104105148821 133.054600592703
88 -33.8237912403668 132.867647797533
89 -33.4384259779102 132.680931602263
90 -33.0543205941704 132.494451965059
91 -32.6714809558057 132.308208844085
92 -32.2899129294743 132.122202197506
93 -31.9096223818347 131.936431983487
94 -31.5306151795449 131.750898160194
95 -31.1528971892633 131.565600685792
96 -30.7764742776482 131.380539518445
97 -30.4013523113577 131.195714616319
98 -30.0275371570503 131.011125937579
99 -29.6550346813841 130.826773440390
100 -29.2838507510175 130.642657082916
101 -28.9139912326086 130.458776823324
102 -28.5454619928158 130.275132619778
103 -28.1782688982973 130.091724430442
104 -27.8124178157114 129.908552213483
105 -27.4479146117164 129.725615927065
106 -27.0847651529705 129.542915529354
107 -26.7229753061320 129.360450978514
108 -26.3625509378591 129.178222232710
109 -26.0034979148102 128.996229250108
110 -25.6458221036435 128.814471988873
111 -25.2895293710172 128.632950407169
112 -24.9346255835897 128.451664463162
113 -24.5811166080191 128.270614115017
114 -24.2290083109639 128.089799320899
115 -23.8783065590822 127.909220038972
116 -23.5290172190323 127.728876227403
117 -23.1811461574724 127.548767844356
118 -22.8346992410609 127.368894847996
119 -22.4896823364560 127.189257196488
120 -22.1461013103160 127.009854847997
121 -21.8039620292991 126.830687760689
122 -21.4632703600637 126.651755892728
123 -21.1240321692679 126.473059202280
124 -20.7862533235701 126.294597647510
125 -20.4499396896284 126.116371186582
126 -20.1150971341013 125.938379777662
127 -19.7817315236469 125.760623378914
128 -19.4498487249235 125.583101948505
129 -19.1194546045895 125.405815444598
130 -18.7905550293029 125.228763825359
131 -18.4631558657222 125.051947048954
132 -18.1372629805056 124.875365073546
133 -17.8128822403114 124.699017857302
134 -17.4900195117977 124.522905358386
135 -17.1686806616230 124.347027534963
136 -16.8488715564454 124.171384345199
137 -16.5305980629232 123.995975747258
138 -16.2138660477148 123.820801699306
139 -15.8986813774783 123.645862159508
140 -15.5850499188720 123.471157086028
141 -15.2729775385542 123.296686437032
142 -14.9624701031832 123.122450170684
143 -14.6535334794172 122.948448245151
144 -14.3461735339146 122.774680618597
145 -14.0403961333335 122.601147249186
146 -13.7362071443322 122.427848095085
147 -13.4336124335691 122.254783114458
148 -13.1326178677023 122.081952265470
149 -12.8332293133902 121.909355506287
150 -12.5354526372909 121.736992795072
151 -12.2392937060629 121.564864089993
152 -11.9447583863643 121.392969349213
153 -11.6518525448534 121.221308530897
154 -11.3605820481885 121.049881593211
155 -11.0709527630278 120.878688494320
156 -10.7829705560296 120.707729192389
157 -10.4966412938523 120.537003645582
158 -10.2119708431539 120.366511812065
159 -9.92896507059294 120.196253650004
160 -9.64762984282751 120.026229117562
161 -9.36797102651596 119.856438172906
162 -9.08999448831651 119.686880774200
163 -8.81370609488747 119.517556879609
164 -8.53911171288707 119.348466447299
165 -8.26621720897362 119.179609435434
166 -7.99502844980533 119.010985802179
167 -7.72555130204052 118.842595505700
168 -7.45779163233743 118.674438504162
169 -7.19175530735435 118.506514755729
170 -6.92744819374953 118.338824218567
171 -6.66487615818123 118.171366850841
172 -6.40404506730773 118.004142610716
173 -6.14496078778731 117.837151456357
174 -5.88762918627821 117.670393345928
175 -5.63205612943872 117.503868237596
176 -5.37824748392711 117.337576089526
177 -5.12620911640163 117.171516859881
178 -4.87594689352055 117.005690506828
179 -4.62746668194215 116.840096988531
180 -4.38077434832469 116.674736263155
181 -4.13587575932645 116.509608288867
182 -3.89277678160568 116.344713023829
183 -3.65148328182065 116.180050426209
184 -3.41200112662963 116.015620454170
185 -3.17433618269091 115.851423065878
186 -2.93849431666271 115.687458219498
187 -2.70448139520336 115.523725873194
188 -2.47230328497106 115.360225985133
189 -2.24196585262413 115.196958513479
190 -2.01347496482082 115.033923416397
191 -1.78683648821939 114.871120652052
192 -1.56205628947812 114.708550178610
193 -1.33914023525527 114.546211954235
194 -1.11809419220911 114.384105937092
195 -0.898924026997904 114.222232085347
196 -0.681635606279926 114.060590357164
197 -0.466234796713451 113.899180710709
198 -0.252727464956735 113.738003104147
199 -0.0411194776680333 113.577057495643];
plot3(data1(:,1),data1(:,2),data1(:,3)); hold on
plot3(data2(:,1),data2(:,2),data2(:,3));
grid on
legend('data1','data2')
hold off
When i tried the interp2 function, it told me that a ndgrid structure is needed, so i checked an found out, that the y- values of the data are not evenly spaced. so i turned to the griddata function.
[xq,yq] = meshgrid(0:200,-80:0);
data_int = griddata([1:200 ;1:200]',[data1(:,2) data2(:,2)],[data1(:,3) data2(:,3)],xq,yq );
contour(xq,yq,data_int); hold on
grid minor
plot3(data1(:,1),data1(:,2),data1(:,3),LineWidth=3);
plot3(data2(:,1),data2(:,2),data2(:,3),LineWidth=3);
legend('interpolated data', 'data1','data2')
hold off
it does its job but i realized the data below the blue line is not valid, but it still interpolates z values there.
does anyone has a idea how to get rid of this interpolated data?
my guess is that it is a side product of the triangulation. is there maybe a solution by deleting the data below the blue line?
thank you in advance
kind regards

채택된 답변

Githin George
Githin George 2023년 10월 11일
Hi Lukas,
I understand you would like to cut away the invalid datapoints in the final grid obtained. These datapoints are generated by the contour and can be eliminated by setting those specific values to ‘NaN’. I have added a few lines of code to the script in order to do the same.
[xq,yq] = meshgrid(0:200,-80:0);
data_int = griddata([1:200 ;1:200]',[data1(:,2) data2(:,2)],[data1(:,3) data2(:,3)],xq,yq );
% Code to Remove the invalid data points.
mask = yq < interp1(data1(:,1), data1(:,2), xq);
data_int(mask) = NaN
% Code for plotting
contour(xq,yq,data_int); hold on
grid minor
plot3(data1(:,1),data1(:,2),data1(:,3),LineWidth=3);
plot3(data2(:,1),data2(:,2),data2(:,3),LineWidth=3);
legend('interpolated data', 'data1','data2')
hold off
I hope this helps.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by