フィルターのクリア

Usage of Special character " @ " in function handle ???

4 ビュー (過去 30 日間)
Anjireddy Thatiparthy
Anjireddy Thatiparthy 2012 年 11 月 12 日
can anyone please explain me the complete usage and working of " @ " in function handle ?.
Please explain the working of following functions.
sincos = @(x) sin(x) + cos(x);
w = @(x,t,c) cos(x-c*t);
fzero(@sin,3)

回答 (1 件)

Matt J
Matt J 2012 年 11 月 12 日
編集済み: Matt J 2012 年 11 月 12 日
In your first 2 examples, the @ is used to define an Anonymous Function.
In the 3rd example, it prompts MATLAB to look for a function defined somewhere on the path (here, the sin() function) and return a handle to it.
  3 件のコメント
Walter Roberson
Walter Roberson 2012 年 11 月 13 日
@ is mostly used to be able to pass a reference to a function as a parameter. The code can then invoke whichever function was passed to it without having to be specifically programmed to handle that situation.
In your example of fzero(), fzero() repeatedly invokes whichever function is passed in to it, on a single argument, trying to determine the argument at which the function will return zero. All that fzero has to know about the function is the reference to it (the function handle formed by the @ operator), and that it takes a single argument. In this way, quite general routines can be constructed.
Anjireddy Thatiparthy
Anjireddy Thatiparthy 2012 年 11 月 15 日
Thank you Mr. Walter Roberson

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by