In this programe of line fitting for y=mx+c , i get problem in "cfit". plz help me to get right program for this y=mx+c.

조회 수: 2 (최근 30일)
x=[0:100]';
y=x;
n=randn(101,1);
yi=y+n;
m=input('inital value slope');
dm=input('incremental value in m');
c=input('inital value contsant');
dc=input('incremental value in c');
niter=input('no. of iterstions');
for a=1:niter;
mx=[m-dm,m,m+dm];
cx=[c-dc,c,c+dc];
for b=1:3;
e=1:3;
my=mx(b);
cy=cx(e);
yfit=my*x;
cfit=my*x*n+cy*(mx);
yerr(b,e)=sum((cfit-yi).^2);
end;
[z indx]=sort(yerr);
m= mx(indx(1));
dm=dm/2;
end;
yfit1=m*x;
plot(x,yfit1,'r');
hold on
plot(x,yi,'x');

답변 (1개)

Arthur
Arthur 2013년 9월 12일
The dimensions of your arrays in not consistent. In order to add or multiply two variables, they have to have the same dimensions, or to be scalars. But in your script, my is 1x1, x is 101x1, n is 101x1, cy is 3x1 and mx is 3x1.
I'm not sure what you're trying to achieve, but probably you should fix the dimensions of cy and mx.

카테고리

Help CenterFile Exchange에서 Fit Postprocessing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by