To find the best order for polyfit in MATLAB, you can use the following steps:
15 chars2 lines
212 chars7 lines
In this code, x
and y
are your data vectors, and computeRsquared
is a function that computes a goodness of fit metric, such as R-squared.
63 chars4 lines
This plot can help you identify the order that gives the best balance between goodness of fit and model complexity.
Note that this approach assumes that a polynomial model is appropriate for your data. If you are not sure, you may want to consider other types of models as well.
gistlibby LogSnag