如果您不知道先验您的中间范围是什么,但您知道您希望丢弃曲线起点和终点的异常值,并且如果您有统计工具箱,您可以使用ROBUSTFIT,并且只保留内部。
M=[-99 -99 -44.5 -7.375 -5.5 -1.666666667 -1.333333333 -1.285714286 0.436363636 2.35 3.3 4.285714286 5.052631579 6.2 7.076923077 7.230769231 7.916666667 9.7 10.66666667 16.16666667 17.4 19.2 19.6 20.75 24.25 34.5 49.5];
%# robust linear regression
x = find(isfinite(M)); %# eliminate NaN or Inf
[u,s]=robustfit(x,M(x));
%# inliers have a weight > 0.25 (raise this value to be stricter)
inlierIdx = s.w > 0.25;
middleRangeX = x(inlierIdx)
middleRangeValues = M(x(inlierIdx))
%# plot with the regression in red and the good values in green
plot(x,M(x), -b. ,x,u(1)+u(2)*x, r )
hold on,plot(middleRangeX,middleRangeValues, *r )
middleRangeX =
Columns 1 through 21
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Column 22
25
middleRangeValues =
Columns 1 through 10
-7.375 -5.5 -1.6667 -1.3333 -1.2857 0.43636 2.35 3.3 4.2857 5.0526
Columns 11 through 20
6.2 7.0769 7.2308 7.9167 9.7 10.667 16.167 17.4 19.2 19.6
Columns 21 through 22
20.75 24.25