使用Matlab进行拟合是图像处理中线条变换的一个重点内容,本文将详解Matlab中的直线拟合和曲线拟合用法。
关键函数:
fittype
Fit type for curve and surface fitting
Syntax
ffun = fittype(libname)
ffun = fittype(expr)
ffun = fittype({expr1,...,exprn})
ffun = fittype(expr, Name, Value,...)
ffun= fittype({expr1,...,exprn}, Name, Value,...)
/***********************************线性拟合***********************************/
线性拟合公式:
coeff1 * term1 + coeff2 * term2 + coeff3 * term3 + ...
其中,coefficient是系数,term都是x的一次项。
线性拟合Example:
Example1: y=kx+b;
法1:
x=[1,1.5,2,2.5,3];y=[0.9,1.7,2.2,2.6,3];
p=polyfit(x,y,1);
x1=linspace(min(x),max(x));
y1=polyval(p,x1);
plot(x,y,'*',x1,y1);
结果:p = 1.0200 0.04