I'm trying to optimize my code where I want to discover which linear regression model is optimal to use, looking at R^2. So far this is what I've come up with (where M1 and M2 are parts of two tables):
[linear1, gof]=fit(M1,M2,'poly1');linear1_R2=gof.rsquare%
[linear2, gof]=fit(M1,M2,'poly2');linear2_R2=gof.rsquare% [linear3, gof]=fit(M1,M2,'poly3');linear3_R2=gof.rsquare...
I want to do this until poly9 and it feels like it can be optimized. I was thinking about doing a for loop where the program (1) will run all the fit functions and (2) display which one gives the highest R^2 and what that value is, but I'm not sure how to proceed.
Hope someone can help, thanks in advance!
Best Answer