polyfit returns a vector of coefficients which has one more entries as the given degree. degree 2 has 3 entries and so on. But you are trying to store the results in a scalar each time.
Look at cell arrays.
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!