function [Height, Position, Width]=gaussfit(x,y) % Converts y-axis to a log scale, fits a parabola % (quadratic) to the (x,ln(y)) data, then calculates % the position, width, and height of the % Gaussian from the three coefficients of the % quadratic fit. This works only if the data have % no baseline offset (that is, trends to zero far off the % peak) and if there are no zeros or negative values in y. % Example: [Height, Position, Width]=cqf([1 2 3],[1 2 1]) % returns Height = 2, Position = 2, Width = 2.0019 z=log(y); coef=polyfit(x,z,2); a=coef(3); b=coef(2); c=coef(1); Height=exp(a-c*(b/(2*c))^2); Position=-b/(2*c); Width=2.35703/(sqrt(2)*sqrt(-c));