What is the benefit of using a function handle?

y = @(x) x; vs y=x... why would I use one over the other? Any benefit to the function handle?

 採用された回答

per isakson
per isakson 2015 年 1 月 24 日

1 投票

IMO: the main benefit is that it can be passed to other functions as an argument.

その他の回答 (2 件)

Zoltán Csáti
Zoltán Csáti 2015 年 1 月 24 日

0 投票

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 2015 年 1 月 24 日

0 投票

The function handle is for example helpful for integration. Maybe you can have a look at fplot, which makes use of function handles.

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

質問済み:

2015 年 1 月 24 日

回答済み:

2015 年 1 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by