Passing predefined variables into matlab's fit function
Mostrar comentarios más antiguos
I have a fit using a custom equation' I have some coefficients that are predefined and don't need to be fitted against, how can i pass this into the fit function model without having to write them manually?
Respuesta aceptada
Más respuestas (1)
Use anonymous functions, e.g.
f = @(x,y) x + y;
g = @(y) f(4,y);
turns f, a function of 2 variables into g, a function of 1 variable with the other hard-coded. More usefully you can equally do e.g.
a = 4;
g = @(y) a + y;
where a has been defined ahead of the function definition so is fixed when you actually call g and you just pass in y.
If it is being passed to some other function as a function handle that expects one variable argument, to be optimised then you can do this to have a function of as many variables as you want, where n-1 of them are predefined.
1 comentario
Optical_Stress
el 16 de Mzo. de 2018
Categorías
Más información sobre Linear and Nonlinear Regression en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!