From: Giga Babs on
Hya

If I wrote :
plot(x,y);
CoeffReg = polyfit(x(:),y(:),1)';
CoeffReg(1);

I got the coefficients of my linear regression in the workspace but I can't see the fit in the figure....
How can I see the fit in the figure???

Thanks
From: Husam Aldahiyat on
"Giga Babs" <bdmendy(a)gmail.com> wrote in message <hn59af$rfs$1(a)fred.mathworks.com>...
> Hya
>
> If I wrote :
> plot(x,y);
> CoeffReg = polyfit(x(:),y(:),1)';
> CoeffReg(1);
>
> I got the coefficients of my linear regression in the workspace but I can't see the fit in the figure....
> How can I see the fit in the figure???
>
> Thanks

You'll need to plot it yourself.

t = linspace(min(x),max(x),100);
p = polyval(CoeffReg,t);
hold on
plot(t,p)
From: Pekka Kumpulainen on
"Giga Babs" <bdmendy(a)gmail.com> wrote in message <hn59af$rfs$1(a)fred.mathworks.com>...
> Hya
>
> If I wrote :
> plot(x,y);
> CoeffReg = polyfit(x(:),y(:),1)';
> CoeffReg(1);
>
> I got the coefficients of my linear regression in the workspace but I can't see the fit in the figure....
> How can I see the fit in the figure???
>
> Thanks

Read the documentation of polyfit. There is an example.
From: Wayne King on
"Giga Babs" <bdmendy(a)gmail.com> wrote in message <hn59af$rfs$1(a)fred.mathworks.com>...
> Hya
>
> If I wrote :
> plot(x,y);
> CoeffReg = polyfit(x(:),y(:),1)';
> CoeffReg(1);
>
> I got the coefficients of my linear regression in the workspace but I can't see the fit in the figure....
> How can I see the fit in the figure???
>
> Thanks

You have the coefficients of the polynomial, but you have to construct it as a vector by defining a range of x values and then evaluating the polynomial at those x values. Say your x range from [0,10], create an x vector, x1

x1=0:.01:10;
y1 = CoeffReg(1)+CoeffReg(2)*x1;
hold on; % to hold your other plot
plot(x1,y1,'k')

Hope that helps,
Wayne
From: Giga Babs on
"Wayne King" <wmkingty(a)gmail.com> wrote in message <hn5a6i$n43$1(a)fred.mathworks.com>...
> "Giga Babs" <bdmendy(a)gmail.com> wrote in message <hn59af$rfs$1(a)fred.mathworks.com>...
> > Hya
> >
> > If I wrote :
> > plot(x,y);
> > CoeffReg = polyfit(x(:),y(:),1)';
> > CoeffReg(1);
> >
> > I got the coefficients of my linear regression in the workspace but I can't see the fit in the figure....
> > How can I see the fit in the figure???
> >
> > Thanks
>
> You have the coefficients of the polynomial, but you have to construct it as a vector by defining a range of x values and then evaluating the polynomial at those x values. Say your x range from [0,10], create an x vector, x1
>
> x1=0:.01:10;
> y1 = CoeffReg(1)+CoeffReg(2)*x1;
> hold on; % to hold your other plot
> plot(x1,y1,'k')
>
> Hope that helps,
> Wayne

Thank you all
I got it !!