From: Ender on
"Wayne King" <wmkingty(a)gmail.com> wrote in message <i2v38k$pkc$1(a)fred.mathworks.com>...
> "Ender " <jr147(a)msstate.edu> wrote in message <i2v0tk$pcr$1(a)fred.mathworks.com>...
> > "Wayne King" <wmkingty(a)gmail.com> wrote in message <i2urdc$2mj$1(a)fred.mathworks.com>...
> > > "Ender " <jr147(a)msstate.edu> wrote in message <i2uphd$fo$1(a)fred.mathworks.com>...
> > > > I would like to know how to interpret a graph and obtain a trend line equation similiar to what one can do in Excel. I know that MatLab is more powerful than Excel, and I am hoping I can do this without having to write the data to Excel than create the trend line equation.
> > > >
> > > >
> > > > --Ender--
> > >
> > > Hi Ender, There are certainly many,many tools in MATLAB to fit all sorts of different models to data. I'll assume here that when you say trend line, you mean the best linear fit, and I'll try to give you a very simple way. The simplest way uses lsline() which requires the Statistics Toolbox
> > >
> > > x = 0:100;
> > > y = 0.5*x+randn(size(x));
> > > % y is your data
> > > plot(x,y,'k*');
> > > h = lsline;
> > > set(h,'linewidth',2,'color',[0 0 1]);
> > >
> > > % you don't need the Statistics Toolbox for this next way
> > > % Fit the best 1st order polynomial to your data
> > > P = polyfit(x,y,1);
> > > % P(1) is the slope of the line and P(2) is the Y-intercept
> > > yfit = P(1)*x+P(2);
> > > plot(x,y,'k*');
> > > hold on;
> > > plot(x,yfit);
> > >
> > > Hope that helps,
> > > Wayne
> >
> > Sort of. My data is not really linear, but this is a start. Can Matlab give me an equation that best describes this data?
> >
> > Also, can I change the curve fit to something besides a line. I would like something that fits my data better. If you show me how, I can send you my graph and then you could show me how to fit the data.
> >
> > --Ender--
>
> Hi Ender, Specific recommendations depend on what toolboxes you have licensed. For example, both the Curve Fitting and Statistics Toolbox have a number of options for fitting models to your data.
>
> The polyfit() example (base MATLAB) I gave you can easily be used with higher-order polynomials. For example:
>
> P = polyfit(x,y,2);
>
> fits a quadratic to the data. Change the final input to a 3 and you get a cubic fit and so on.
>
> Do you have the Statistics and/or Curve Fitting Toolbox? Enter
> >>ver
> at the command line to see what you have installed.
>
> Wayne

I will try your options, but I do have the curve fit toolbox.

--Ender--
From: TideMan on
On Jul 31, 7:39 am, "Ender " <jr...(a)msstate.edu> wrote:
> "Wayne King" <wmkin...(a)gmail.com> wrote in message <i2v38k$pk...(a)fred.mathworks.com>...
> > "Ender " <jr...(a)msstate.edu> wrote in message <i2v0tk$pc...(a)fred.mathworks.com>...
> > > "Wayne King" <wmkin...(a)gmail.com> wrote in message <i2urdc$2m...(a)fred..mathworks.com>...
> > > > "Ender " <jr...(a)msstate.edu> wrote in message <i2uphd$f...(a)fred.mathworks.com>...
> > > > > I would like to know how to interpret a graph and obtain a trend line equation similiar to what one can do in Excel. I know that MatLab is more powerful than Excel, and I am hoping I can do this without having to write the data to Excel than create the trend line equation.
>
> > > > > --Ender--
>
> > > > Hi Ender, There are certainly many,many tools in MATLAB to fit all sorts of different models to data. I'll assume here that when you say trend line, you mean the best linear fit, and I'll try to give you a very simple way. The simplest way uses lsline() which requires the Statistics Toolbox
>
> > > > x = 0:100;
> > > > y = 0.5*x+randn(size(x));
> > > > % y is your data
> > > > plot(x,y,'k*');
> > > > h = lsline;
> > > > set(h,'linewidth',2,'color',[0 0 1]);
>
> > > > % you don't need the Statistics Toolbox for this next way
> > > > % Fit the best 1st order polynomial to your data
> > > > P = polyfit(x,y,1);
> > > > % P(1) is the slope of the line and P(2) is the Y-intercept
> > > > yfit = P(1)*x+P(2);
> > > >  plot(x,y,'k*');
> > > > hold on;
> > > > plot(x,yfit);
>
> > > > Hope that helps,
> > > > Wayne
>
> > > Sort of. My data is not really linear, but this is a start. Can Matlab give me an equation that best describes this data?
>
> > > Also, can I change the curve fit to something besides a line. I would like something that fits my data better. If you show me how, I can send you my graph and then you could show me how to fit the data.
>
> > > --Ender--
>
> > Hi Ender, Specific recommendations depend on what toolboxes you have licensed. For example, both the Curve Fitting and Statistics Toolbox have a number of options for fitting models to your data.
>
> > The polyfit() example (base MATLAB) I gave you can easily be used with higher-order polynomials. For example:
>
> > P = polyfit(x,y,2);
>
> > fits a quadratic to the data. Change the final input to a 3 and you get a cubic fit and so on.
>
> > Do you have the Statistics and/or Curve Fitting Toolbox? Enter
> > >>ver
> > at the command line to see what you have installed.
>
> > Wayne
>
> I will try your options, but I do have the curve fit toolbox.
>
> --Ender--

You have the Matlab curve fitting toolbox and yet you asked whether
Matlab could do a linear fit like Excel can?
Didn't you think to look at the toolbox before asking the question
here?
From: Wayne King on
"Ender " <jr147(a)msstate.edu> wrote in message <i2v9oo$qqv$1(a)fred.mathworks.com>...
> "Wayne King" <wmkingty(a)gmail.com> wrote in message <i2v38k$pkc$1(a)fred.mathworks.com>...
> > "Ender " <jr147(a)msstate.edu> wrote in message <i2v0tk$pcr$1(a)fred.mathworks.com>...
> > > "Wayne King" <wmkingty(a)gmail.com> wrote in message <i2urdc$2mj$1(a)fred.mathworks.com>...
> > > > "Ender " <jr147(a)msstate.edu> wrote in message <i2uphd$fo$1(a)fred.mathworks.com>...
> > > > > I would like to know how to interpret a graph and obtain a trend line equation similiar to what one can do in Excel. I know that MatLab is more powerful than Excel, and I am hoping I can do this without having to write the data to Excel than create the trend line equation.
> > > > >
> > > > >
> > > > > --Ender--
> > > >
> > > > Hi Ender, There are certainly many,many tools in MATLAB to fit all sorts of different models to data. I'll assume here that when you say trend line, you mean the best linear fit, and I'll try to give you a very simple way. The simplest way uses lsline() which requires the Statistics Toolbox
> > > >
> > > > x = 0:100;
> > > > y = 0.5*x+randn(size(x));
> > > > % y is your data
> > > > plot(x,y,'k*');
> > > > h = lsline;
> > > > set(h,'linewidth',2,'color',[0 0 1]);
> > > >
> > > > % you don't need the Statistics Toolbox for this next way
> > > > % Fit the best 1st order polynomial to your data
> > > > P = polyfit(x,y,1);
> > > > % P(1) is the slope of the line and P(2) is the Y-intercept
> > > > yfit = P(1)*x+P(2);
> > > > plot(x,y,'k*');
> > > > hold on;
> > > > plot(x,yfit);
> > > >
> > > > Hope that helps,
> > > > Wayne
> > >
> > > Sort of. My data is not really linear, but this is a start. Can Matlab give me an equation that best describes this data?
> > >
> > > Also, can I change the curve fit to something besides a line. I would like something that fits my data better. If you show me how, I can send you my graph and then you could show me how to fit the data.
> > >
> > > --Ender--
> >
> > Hi Ender, Specific recommendations depend on what toolboxes you have licensed. For example, both the Curve Fitting and Statistics Toolbox have a number of options for fitting models to your data.
> >
> > The polyfit() example (base MATLAB) I gave you can easily be used with higher-order polynomials. For example:
> >
> > P = polyfit(x,y,2);
> >
> > fits a quadratic to the data. Change the final input to a 3 and you get a cubic fit and so on.
> >
> > Do you have the Statistics and/or Curve Fitting Toolbox? Enter
> > >>ver
> > at the command line to see what you have installed.
> >
> > Wayne
>
> I will try your options, but I do have the curve fit toolbox.
>
> --Ender--

Hi Ender, Since you have the Curve Fitting Toolbox. An easy place to start is to use cftool()
If you enter
>>cftool

This opens a GUI from which you can import your data from the MATLAB workspace and choose from a large number of fit options.

Wayne
Wayne
First  |  Prev  | 
Pages: 1 2
Prev: Redefine 0/0
Next: importing into Excel