Paris
Paris

Reputation: 15

How to get the histogram fit function?

I want to have 7_order polynomial fit for my histogram, but I don’t want to plot it, I need the polynomial function with its coefficients to get new data. How can I get this?

Upvotes: 0

Views: 225

Answers (1)

If you want to get new data from a polynomial function (that fits your original data points), you must first find the coefficients using polyfit.

In the example below, you calculate the 7th-degree polynomial that variable p holds and you generate new data, using polyval, so y1 holds these data.

x = linspace(0,4*pi,10);
y = sin(x);
p = polyfit(x,y,7);

x1 = linspace(0,4*pi);
y1 = polyval(p,x1);

Upvotes: 1

Related Questions