Thread Subject: Using m code generated by curve fitting tool box

Subject: Using m code generated by curve fitting tool box

From: Pawan

Date: 2 Dec, 2008 05:41:01

Message: 1 of 3

Hi, I need a big help to extract the information generated by the m-file generated by curve fitting tool box. I used "xdata" and "ydata" and fitted it into a sine wave using curve fitting tool box. I used "Sum of Sin functions" as type of fit and "a1*sin(b1*x+c1)" as type of sin functions. Then it generated a sine wave for me and I saved it as m-file. Now I am using it as the function of my main code to do the curvefitting. But I want to extract the values a1, b1 and c1 generated by that function(m-code). It is saved as "cf_" under the automatically generated variable of m code which I can see in the workspace but it is not in 1-D or 2-D array, rather it comes up with text meassage in the workspace (in the class field of workspace it is written "cfit" which is normally "double" for other variables) so I cannot store it in other variables for further processing using the codes in the program. Is it possible to extract that information?
Also is there any command for sinusoidal fitting similar to "polyfit" or "poly3"(which are used for polynomials)?

Subject: Using m code generated by curve fitting tool box

From: Jiro Doke

Date: 2 Dec, 2008 06:10:19

Message: 2 of 3

"Pawan " <pawan@waikato.ac.nz> wrote in message <gh2hpd$av5$1@fred.mathworks.com>...
> Hi, I need a big help to extract the information generated by the m-file generated by curve fitting tool box. I used "xdata" and "ydata" and fitted it into a sine wave using curve fitting tool box. I used "Sum of Sin functions" as type of fit and "a1*sin(b1*x+c1)" as type of sin functions. Then it generated a sine wave for me and I saved it as m-file. Now I am using it as the function of my main code to do the curvefitting. But I want to extract the values a1, b1 and c1 generated by that function(m-code). It is saved as "cf_" under the automatically generated variable of m code which I can see in the workspace but it is not in 1-D or 2-D array, rather it comes up with text meassage in the workspace (in the class field of workspace it is written "cfit" which is normally "double" for other variables) so I cannot store it in other variables for further processing using the codes in the program. Is it possible to extract that information?
> Also is there any command for sinusoidal fitting similar to "polyfit" or "poly3"(which are used for polynomials)?

Pawan,

That variable is a MATLAB object of class "cfit" (as opposed to "double"). It is an object that contains all the necessary information regarding the curve fit. You can read more about it here:

(type the following in MATLAB)
web([docroot '/toolbox/curvefit/bqxox7w.html'])

(if in a regular browser)
http://www.mathworks.com/access/helpdesk/help/toolbox/curvefit/bqxox7w.html

Look at the section titled "Curve Fitting Methods". Those are the functions that you can call on the "cfit" object. For example, if you want to get the coefficient values, type

coeffvalues(cf_)

If you want confidence intervals for the coefficients,

confint(cf_)

If you want to plot the fitted curve,

plot(cf_)

It's quite powerful.

As you can see from the m-file, the fit is performed by using the FITTYPE and FIT functions. There is no unique function like POLYFIT. FITTYPE and FIT are functions from the Curve Fitting Toolbox for performing various types of fits with just those functions.

Hope this helps.

jiro

Subject: Using m code generated by curve fitting tool box

From: Pawan

Date: 2 Dec, 2008 19:22:02

Message: 3 of 3

"Pawan " <pawan@waikato.ac.nz> wrote in message <gh2hpd$av5$1@fred.mathworks.com>...
> Hi, I need a big help to extract the information generated by the m-file generated by curve fitting tool box. I used "xdata" and "ydata" and fitted it into a sine wave using curve fitting tool box. I used "Sum of Sin functions" as type of fit and "a1*sin(b1*x+c1)" as type of sin functions. Then it generated a sine wave for me and I saved it as m-file. Now I am using it as the function of my main code to do the curvefitting. But I want to extract the values a1, b1 and c1 generated by that function(m-code). It is saved as "cf_" under the automatically generated variable of m code which I can see in the workspace but it is not in 1-D or 2-D array, rather it comes up with text meassage in the workspace (in the class field of workspace it is written "cfit" which is normally "double" for other variables) so I cannot store it in other variables for further processing using the codes in the program. Is it possible to extract that information?
> Also is there any command for sinusoidal fitting similar to "polyfit" or "poly3"(which are used for polynomials)?



Hi Jiro,

I tried your suggestion and it worked. Hurray. You are genius. Thank you so much.

Pawan

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
objects Jiro Doke 2 Dec, 2008 01:14:37
curve fit Jiro Doke 2 Dec, 2008 01:14:27
rssFeed for this Thread

Contact us at files@mathworks.com