# How to Do Polynomial Curve Fitting in Matlab

Polynomial curve fitting is a common task for data analysts in many fields of science, engineering and social science.  The standard method to fit a curve to data is to use the least squares method.  In this method, the coefficients of the estimated polynomial are determined by minimizing the squares of errors between the data points and fitted curve.  This method is used to determine the relationship between an independent and dependent variable.  The common term regression line is used for a first-degree polynomial.  Matlab has a simple function called polyfit that allows an analyst to use the least squares method.  In this post, a simple example of polyfit is presented to determine the relationship between two variables in a noisy environment.

# Dynamic Variable Names in Matlab

Assume that you want to create a variable in Matlab whose name is contingent on factors that are unknown before the program runs.  For example, you may want to attach a time or date stamp to the end of a variable name.  You may also have variable names stored in a string or cell array that you want to instantiate as variables.  The best way to accomplish these tasks in Matlab is to use the eval function.  In the following examples, we’ll show you how to do these tasks.