i have some 3d data to which i would like to fit a curve.
i already searched thourgh this newsgroup and some other sites and
found the hint to do that with lsqcurvefit. that sounds good to me
and i would like to try it but honestly i just don't get it. i mean i
read the help text and everything but i still have no idea how to
start or do it.
so i wanted to ask if someone can help me out with an example or
something?
thank ya.
simone
Keep in mind that the XDATA you pass to LSQCURVEFIT does not have to be a
vector; you can pass a multi-column matrix, one column per independent
variable, for the XDATA parameter. As long as your function to be fitted
can pull off each column and treat it as an independent variable, yoiu
should be all set.
As a sample objective function:
function v = fitfun(coeff, xdata)
x = xdata(:,1);
y = xdata(:,2);
v = coeff(1)+coeff(2)*x+coeff(3)*x.^2+coeff(4)*y+coeff(5)*y.^2;
This fits z = a+b*x+c*x^2+d*y+e*y^2.
--
Steve Lord
sl...@mathworks.com
for using lsqcurvefit for a curve in 3d, i.e. some thing like
(x(t),y(t),z(t))
having data (x(i),y(i),z(i)) i=1,.,N you must have a model for the curve:
x(t) = FX(param,t)
y(t) = FY(param,t)
z(t) = FZ(param,t)
where param are the parameters to be fitted and the three functions FX,FY andFZ
are not neccessarily of the same type. If I understand your problem right,
then you have simply those
data points and want a curve trough these points, not a specific model.
then using splines is a good idea: take an artificial parameter t for
your curve points . a natural choice would be the arclength of the interpolating
piecewise linear arc. (!! this assumes that you have the order in which the curve
goes through the points) so
t(1)=0,
t(i)=t(i-1)+norm(P(i)-P(i-1)); i=2,...,n with P(i)=[x(i),y(i),z(i)];
then compute 3 splines (independently) through the data (t(i),x(i))
(t(i),y(i)), (t(i),z(i)) and you have your curve
in the form
(x,y,z)=(s1(t),s2(t),s3(t)), 0<=t<= t_end=t(n)
the normal cubic spline
might be somewhat wavy, hence it might be advisable to use a spline under tension
instead. this depeds a lot on your data, best try it out on a representative set
of examples
hth
peter
K Nagarajoo
On 22 Apr 2004 17:27:27 -0700, Joel Bondurant wrote:
>You can fit 3D data with a single click, and get beautiful 3D graphs
>in realtime with TableCurve 3D from www.systat.com. They have a
>30-day demo that will allow you to do the fitting in seconds with
>graphs and matlab code output. No coding or supplying models is
>required. TableCurve 3D will fit thousands of models to your data in
>seconds with a few mouse clicks.
>
>-Joel
>
>simone <simone...@biocam.de> wrote in message
news:<eeda1...@webx.raydaftYaTP>...