Re: how can I alter the x-data of a cfit object after fitting?
- From: "Jon Cherrie" <jcherrie.n.o.s.p.a.m.@xxxxxxxxxxxxxxx>
- Date: Thu, 23 Aug 2007 10:51:23 +0000 (UTC)
Hi Matthew,
The CFIT object doesn't hold the x-data, so, unfortunately,
there is no hope of you scaling that.
I suspect the problem with fitting the Gaussian curve to the
scaled data is due to the start points (initial guess) of
the coefficients. CFTOOL will have worked out a good
starting point for the original data, but these probably
aren't so good for your scaled data.
In the generated m-file, look for some lines like
st_ = [9 22 4.0191415934240649 ];
set(fo_,'Startpoint',st_);
(where the particular numbers you have will depend on your
data). These three numbers correspond to the coefficients
a1, b1, c1, in
cf =
General model Gauss1:
cf(x) = a1*exp(-((x-b1)/c1)^2)
Coefficients (with 95% confidence bounds):
a1 = 8.45 (7.285, 9.615)
b1 = 0.1446 (0.1372, 0.152)
c1 = 0.06585 (0.05534, 0.07635)
From the formula " a1*exp(-((x-b1)/c1)^2)" we see that "b1"and "c1" are on the same scale as x. Therefore if we scale
the x-data by k then we need to scale the estimates of these
two coefficients by k also. The coefficient "a1" is on the
same scale as y and so shouldn't need any attention in your
case. All going well, scaling these starting values should
improve the quality of the fit.
Cheers,
--Jon.
"Matthew McMahon" <matthew.mcmahon.nospam@xxxxxxxx> wrote in
message <f99sui$7jb$1@xxxxxxxxxxxxxxxxxx>...
Hi MATLAB gurus,
I am fitting histogram data with a Gaussian, using an M-file
I generated from the cftool and have since modified. The
data is derived from an image, and when I plot the histogram
and the fit together I want the independent (x-) axis units
to be calibrated to a physical distance, not just the
distance in pixels. The trouble is that if I do the
calibration first and then feed the data to the fitting
function, the fit messes up (probably because the
calibration factor is << 1).
What I would like to do is to do the fit with the
uncalibrated data (this works fine), and then simply scale
the x-axis points by the calibration factor (for plotting
purposes), without altering the y-axis data. I haven't
found a way to scale the x-axis yet; I've searched the help
for fit, cfit, fittype, fitoptions, and plot(curve fitting
toolbox version) to no avail.
The short form of the question is: How do I access the
x-data of a 'cfit' object after I've done the fit? Is that
possible?
Or, maybe, is there a workaround with the plot function that
will leave the data unchanged but automatically relabel the
ticks?
I'd be happy to share code snippets if it will help.
Thanks,
Matthew
.
- References:
- how can I alter the x-data of a cfit object after fitting?
- From: Matthew McMahon
- how can I alter the x-data of a cfit object after fitting?
- Prev by Date: argment passing problem
- Next by Date: Import from undefault directory
- Previous by thread: how can I alter the x-data of a cfit object after fitting?
- Next by thread: Model beautifier
- Index(es):
Relevant Pages
|