How to pass a function handle if some input argument is fixed?

9 visualizaciones (últimos 30 días)
Mr M.
Mr M. el 20 de Mayo de 2017
Comentada: Stephen23 el 22 de Mayo de 2017
I have to pass a function handle of a single variable function, but I want to use a function with multiple input arguments, and fix some of them. For example I want to pass the handle of single variable function: normpdf(x,10,2).

Respuestas (1)

Walter Roberson
Walter Roberson el 20 de Mayo de 2017
For example,
target = 0.16193;
myfun = @(x) normpdf(x, 10, 2) - target;
fzero(myfun, rand) %example of needing to pass a function of one variable
  2 comentarios
Mr M.
Mr M. el 22 de Mayo de 2017
Yes, thanks, I know this solution by defining a new function. My question is: is it possible to do this in one line?
Stephen23
Stephen23 el 22 de Mayo de 2017
"is it possible to do this in one line?"
Why not try it yourself?:
fzero(@(x)normpdf(x,10,2)-target, rand)

Iniciar sesión para comentar.

Categorías

Más información sobre Parallel Computing Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by