How to create a dynamic function handle?

1 回表示 (過去 30 日間)
Marianna
Marianna 2022 年 11 月 22 日
コメント済み: John D'Errico 2022 年 11 月 22 日
I want to create a dynamic function handle. How to do?
  1 件のコメント
John D'Errico
John D'Errico 2022 年 11 月 22 日
What is a dynamic function handle? If you want a useful answer, you need to ask a clear question.

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

回答 (1 件)

Star Strider
Star Strider 2022 年 11 月 22 日
I have no idea what you are asking.
It is straightforward to create a function handle that accepts various function arguments, either for a specific function or an existing function.
f = @(x,y) exp(-(x.^2 + y.^2)/5);
[X,Y] = ndgrid(-5:0.1:5);
figure
surf(X, Y, f(X,Y))
grid on
.
  2 件のコメント
Marianna
Marianna 2022 年 11 月 22 日
I have this: f=@(v1,v2,v3)(v1*v2^2+v3)
This is particular, but i want to create different functions in a loop.
for example if i=1 the f has this form, but if i=2 the format have to change in (v2*v3^2+v1).
So i need a dynamic f.
Star Strider
Star Strider 2022 年 11 月 22 日
Create the functions you want, then use an if, elseif, else block to choose the function to execute with respect to a particular condition.

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

カテゴリ

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

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by