Why is spline doing weird stuff with my data?
3 次查看(过去 30 天)
显示 更早的评论
Hi. I'm using spline to connect some data and then access the y points of the spline for given x values with ppval. I'm doing that for a bunch of data sets but this particular one just does not want to work. I've checked the data and everything seems alright, it's just a simple logarithmic scaled curve but when I use spline it completely ignores the y data and only gives me a very small straight line.
The first image is what the data is supposed to look like and the bottom one is what spline does (plotting the ppvals of the spline against the X data below). If you could help me solve this problem I'd be very grateful.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/941069/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/941074/image.jpeg)
Here is the X data:
119645.85786265088
146646.66450412222
202133.69044903992
278604.3016284374
352333.87727521197
459740.8056612833
618961.6849525509
929793.9239081189
1353657.7552896568
2017533.4544660104
3407941.7927995715
5039463.074022855
7569590.718466251
12885283.504396986
17897177.517469957
25647779.645364683
42977437.27455605
72013489.07293034
108149289.00328541
159892742.05166098
225546989.37233916
285178383.4446951
389881674.6691441
524761195.13921815
763692546.5841718
1027788923.9640564
1361818994.575842
1920731945.0032642
2708977699.2498612
4067261756.9724545
6202528142.7401905
9758910221.36459
14881929444.601082
23415342901.2511
35708132890.13138
51959273484.34699
78007014748.32399
Here is the Y data:
68.61538461538461
66.97435897435898
64.3076923076923
61.84615384615385
60.001
57.94871794871794
55.69230769230769
52.71794871794873
50.05128205128206
47.282051282051285
43.794871794871796
41.33333333333334
38.769230769230774
35.794871794871796
33.948717948717956
32.10256410256413
29.641025641025664
27.3846153846154
25.743589743589766
24.307692307692335
23.2820512820513
22.46153846153848
21.64102564102565
20.820512820512846
20.10256410256413
19.79487179487181
19.282051282051313
18.974358974359006
18.769230769230802
18.461538461538495
18.37
18.360974358974391
18.350974358974394
18.25641025641029
18.18
18.16
18.15384615384619
0 个评论
回答(1 个)
Stephen23
2022-3-25
编辑:Stephen23
2022-3-25
I don't see any "weird stuff":
X = [119645.85786265088;146646.66450412222;202133.69044903992;278604.3016284374;352333.87727521197;459740.8056612833;618961.6849525509;929793.9239081189;1353657.7552896568;2017533.4544660104;3407941.7927995715;5039463.074022855;7569590.718466251;12885283.504396986;17897177.517469957;25647779.645364683;42977437.27455605;72013489.07293034;108149289.00328541;159892742.05166098;225546989.37233916;285178383.4446951;389881674.6691441;524761195.13921815;763692546.5841718;1027788923.9640564;1361818994.575842;1920731945.0032642;2708977699.2498612;4067261756.9724545;6202528142.7401905;9758910221.36459;14881929444.601082;23415342901.2511;35708132890.13138;51959273484.34699;78007014748.32399];
Y = [68.61538461538461;66.97435897435898;64.3076923076923;61.84615384615385;60.001;57.94871794871794;55.69230769230769;52.71794871794873;50.05128205128206;47.282051282051285;43.794871794871796;41.33333333333334;38.769230769230774;35.794871794871796;33.948717948717956;32.10256410256413;29.641025641025664;27.3846153846154;25.743589743589766;24.307692307692335;23.2820512820513;22.46153846153848;21.64102564102565;20.820512820512846;20.10256410256413;19.79487179487181;19.282051282051313;18.974358974359006;18.769230769230802;18.461538461538495;18.37;18.360974358974391;18.350974358974394;18.25641025641029;18.18;18.16;18.15384615384619];
pp = spline(X,Y);
xq = logspace(5.5,10.5,11);
yq = ppval(pp,xq);
semilogx(X,Y,'r-',xq,yq,'b*')
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Splines 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!