What is the benefit of using a function handle?

2 visualizaciones (últimos 30 días)
JohnS
JohnS el 24 de En. de 2015
Respondida: per isakson el 24 de En. de 2015
y = @(x) x; vs y=x... why would I use one over the other? Any benefit to the function handle?

Respuesta aceptada

per isakson
per isakson el 24 de En. de 2015
IMO: the main benefit is that it can be passed to other functions as an argument.

Más respuestas (2)

Zoltán Csáti
Zoltán Csáti el 24 de En. de 2015
The two statements are not the same. The first one defines a function while the second one is an equality. The two identical forms are
y = @(x) x;
and
function y = some_function(x)
y = x;
end

Kai
Kai el 24 de En. de 2015
The function handle is for example helpful for integration. Maybe you can have a look at fplot, which makes use of function handles.

Categorías

Más información sobre Function Creation 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