problems with fitting curve from matrix data

Hey there, i have some problems to fitting a curve. Both matrix have two columns and the same length, but i get the error:
??? XDATA must be a matrix with one to two columns.
Error in ==> fit at 115 errstr = handleerr('curvefit:fit:xDataMustBeColumnVector', ...
Error in ==> Niederschlag_Trend at 127 [fitobject, R2] = fit(x,y, 'linearinterp');
What I need is the determination coefficient for the double mass curve, if there is any suggestion to solve it another way, i´m happy to hear it :)
%%Homogenitätstest
load(['niederschlag2_' num2str(NS.start_jahr) '-'num2str(NS.end_jahr)]);
load ref81-2010.mat;
testdata = MaxMatrix(:,2);
refdata = RefMat(:,2);
x=testdata(1);
y=refdata(1);
for i=2:length(testdata);
x(i)=x(i-1) + refdata(i);
y(i)=x(i-1) + testdata(i);
end
%%xi=[min(x),max(x)];
%%yi=[min(y),max(y)];
figure(3)
clf
plot(x,y,'*k','LineWidth',2, 'Color','black')
hold on
*[fitobject, R2] = fit(x,y, 'linearinterp');*
%%plot(xi,yi,'r','LineWidth',2,'Color','red');

 채택된 답변

Titus Edelhofer
Titus Edelhofer 2011년 11월 15일

1 개 추천

Hi Eleen,
hard to guess but probably x and y are row vectors. I would preallocate to be sure:
x = zeros(size(testdata));
y = zeros(size(testdata));
x(1) = testdata(1);
y(1) = refdata(1);
for i=2:...
This way x and y are column vectors which fit will better like. BTW, take a look at the function cumsum, which might replace the loop).
Titus

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

질문:

2011년 11월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by