how to make something between quotation automatic!
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Ham Man
el 16 de Ag. de 2022
Comentada: Ham Man
el 16 de Ag. de 2022
I want to make 'poly2' automatic by changing n? How can I do this using for example eval function?
n=2;% 3,4,....
f1 = fit(x,y,'poly2')
0 comentarios
Respuesta aceptada
Steven Lord
el 16 de Ag. de 2022
If you're just fitting polynomials you could use polyfit and polyval, specifying n as the third input argument.
load census
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')
figure
plot(cdate, pop, 'o')
hold on
plot(theFit, '-')
Más respuestas (0)
Ver también
Categorías
Más información sobre Curve Fitting Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!