分段线性拟合matlab代码
Piecewise
linear
fitting/regression
MATLAB
This
method
can
be
used
in
both
linear
regrassion
and
nonlinear
regression.
The
dimension
of
beta
depends
on
the
number
of
coefficient
you
are
seeking.
线性非线性皆适用
本例中要根据数据拟合两段直线,已知两段直线在x轴截距分别为(0,0)和(133,0),断点在0.95max{ydata}处。本文亮点在于利用逻辑语句进行分段函数定义的方法。网上有许多方法都不如此法简洁明了。
参考网站:
code:
clc
clear
all
close
all
load('1.mat')
%x0为断点
x0
=
0.95*xdata(ydata
==
max(ydata));
%定义分段函数,采用匿名函数语法
model
=
@(beta,x)
beta(1).x.(x>0&x=x0&x<1
2021-08-20 15:31:15
30KB
系统开源
1