Why sometimes a matlab function is called without input arguments?

2 ビュー (過去 30 日間)
Muhammad Alhaddad
Muhammad Alhaddad 2022 年 1 月 28 日
コメント済み: Steven Lord 2022 年 1 月 28 日
Hi,
I have seen that matlab function like this
function dx = some_name(x, u, p)
is called as following
model = @some_name;
I couldn't understand why it is called without input arguments and how the results will be.

採用された回答

Stephen23
Stephen23 2022 年 1 月 28 日
編集済み: Stephen23 2022 年 1 月 28 日
"I have seen that matlab function like this function dx = some_name(x, u, p) is called as following model = @some_name;"
That syntax does not call the function.
A function handle creates an object which can be handled just like any other object (e.g. a numeric array, cell array, graphics object, etc.), e.g. passed as an input/output argument or within a function or script. It can be evaluated when required, just like the original function:
fnh = @sin;
fnh(pi/4)
ans = 0.7071
  1 件のコメント
Steven Lord
Steven Lord 2022 年 1 月 28 日
One metaphor for a function handle is that of a phone number. If I want to talk to you while you're in the same room as I am, I can do so directly. If you're not in the same room as I am, I may not be able to talk to you directly. But if I have your phone number, I can call you up and talk to you (basically) wherever you are.
You can execute a function in MATLAB directly or you can "call it on the phone" via its function handle and execute it that way. Using the @ operator is like writing down the function's phone number on a piece of paper. Your phone number on a piece of paper isn't you, but it's a way to contact you.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Compiler についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by