How to change selected data which would give me the line of best fit (R squared close to 1)?

1 次查看(过去 30 天)
I have a range of data
x = -Inf + 0.00000000000000i
-5.94839731081433 + 0.00000000000000i
-4.40441244315510 + 0.00000000000000i
-5.01054824672844 + 0.00000000000000i
-5.79424663098060 + 0.00000000000000i
-4.91523806692085 + 0.00000000000000i
-2.61442132098323 + 3.14159265358979i
-3.99894733505125 + 3.14159265358979i
-2.61265297392781 + 3.14159265358979i
-4.00012588556654 + 0.00000000000000i
-5.20409868989224 + 0.00000000000000i
y = -3.45375423084893
-3.45376083103347
-3.45405094838298
-3.45428146199255
-3.45431857619349
-3.45456107498460
-3.45493413618944
-3.45513888357560
-3.45551262399935
-3.45574790889255
-3.45589974019472
There are 2 things I want to find out.
1. How to set the values of complex numbers in the array x to NaN? 2. How to select the range of data with linear trend and with best fit (R squared close to zero)?

采纳的回答

Richard Brown
Richard Brown 2012-7-4
For the first part
x(logical(imag(x))) = nan;
For the second, your data points are all over the show. Any two will fit a straight line pretty well though :)
More seriously, try either a 1-norm best fit, or a method like RANSAC if you know that a subset of the data should fit a line and the rest are outliers.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by