how to make something between quotation automatic!
3 views (last 30 days)
Steven Lord on 16 Aug 2022
If you're just fitting polynomials you could use polyfit and polyval, specifying n as the third input argument.
n = 2;
[p, s] = polyfit(cdate, pop, n);
plot(cdate, pop, 'o', cdate, polyval(p, cdate, s), '-')
But you can also use fit if you want. There's no need to use eval here, just use string + or char manipulation.
theFit = fit(cdate, pop, "poly" + n, 'Normalize', 'on') % or
theFit2 = fit(cdate, pop, ['poly', num2str(n)], 'Normalize', 'on') % or
theFit2 = fit(cdate, pop, sprintf('poly%d', n), 'Normalize', 'on')
plot(cdate, pop, 'o')