defining a fitting type
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Wout Laeremans
el 12 de En. de 2023
I have written a funcion called Even_fit.m and there are 5 coefficients that need to be found from the fit (a,b,c,d,f) and there is one variable N that I want to load from the workspace, which is already fixed before fitting. My question is how I can load this variable in the fit, since when I do:
ft_even = fittype("Even_fit(x,a,b,c,d,f,N)");
It will also take N as a fitting coefficient, which I do not want.
Thank you!
0 comentarios
Respuesta aceptada
Torsten
el 12 de En. de 2023
Editada: Torsten
el 12 de En. de 2023
My guess is
fitType = @(x,a,b,c,d,f)Even_fit(x,a,b,c,d,f,N);
fit(x,y,fitType)
2 comentarios
Torsten
el 16 de En. de 2023
Editada: Torsten
el 16 de En. de 2023
Put the vector of the independent variable to the end of the input list for your function "EvenFit":
x = linspace(0,1,10).';
y = 3*x.^2 + 0.1*rand(10,1);
n = 12;
fitType = @(a,b,c,x)Even_fit(x,a,b,c,n);
sol = fit(x,y,fitType)
plot(sol,x,y)
function yfit = Even_fit(x,a,b,c,n)
yfit = a*x.^2+b*x+c;
end
Más respuestas (1)
Steven Lord
el 12 de En. de 2023
See the "Create Custom Nonlinear Models and Specify Problem Parameters and Independent Variables" and "Use Anonymous Functions to Work with Problem Parameters and Workspace Variables" examples on the fittype documentation page.
0 comentarios
Ver también
Categorías
Más información sobre Linear and Nonlinear Regression 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!
