0

So matlab help has the following description :

[P, S, MU] = POLYFIT[X,Y,N]

I know what the input variables mean, but i cant calculate the MU "manually". The MU i need for calculating the area of a peak.

I need to convert source code from MATLAB to R, but don't know what's the best to do.

alap
  • 646
  • 1
  • 11
  • 24
  • Where can we find the function? What did you try? Please provide additional information. – Sven Hohenstein Oct 16 '12 at 14:06
  • Its in MATLAB, and i tried to use the function poly() from R to get the same results. It works, same results. But, while boot of them supplies the coefficients, i don't know how to calculate the MU variable provided by the POLYFIT function of Matlab. – alap Oct 16 '12 at 14:11
  • Once you have the function fit, the integrate() function will allow you to calculate the area of a function between two x-limits. – Marc in the box Oct 16 '12 at 14:19
  • Ok, i tried that to but if there are multiple peaks that over lap each other -> how you calculate it ? So i could break into Gaussian signals separate them but there is the problem of limits again ... – alap Oct 16 '12 at 14:26

1 Answers1

2

MU is given as [mu1,mu2] and is used for centering and scaling the data so that the problem will have good numerical properties. mu1 is the mean of x and mu2 is the standard deviation of x.

See info here.

Bitwise
  • 7,577
  • 6
  • 33
  • 50
  • Problem with following your link : for MATLAB std function there is the sd function of R, mean exits but the values don't correspond. Do you want example code ? But i accept you're response when we finish. – alap Oct 16 '12 at 14:33
  • @ZsurzsaLaszlo-Andras so you calculated the mean of X and the std of X and these are not equal to mu1 and mu2? – Bitwise Oct 16 '12 at 14:44
  • Yeah so if i for example calculate it in matlab using the functions and using polyfit the results are not the same. – alap Oct 16 '12 at 14:50
  • 2
    Well I just tried in matlab: x=rand(10,1);y=3*x+1;[p,s,mu]=polyfit(x,y,1) and the mu1,mu2 were equal to mean(x),std(x) so it works. – Bitwise Oct 16 '12 at 14:56