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');

 Respuesta aceptada

Titus Edelhofer
Titus Edelhofer el 15 de Nov. de 2011
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

Más respuestas (0)

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Centro de ayuda y File Exchange.

Preguntada:

el 15 de Nov. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by