フィルターのクリア

Anonymus Function from Input function

1 回表示 (過去 30 日間)
Jose Trevino
Jose Trevino 2016 年 2 月 21 日
コメント済み: Star Strider 2016 年 2 月 22 日
Hi, I am writing a code that takes an input function (f) and then the code does some operations with it. It was using inline function but I prefer to use anonymous function. It was set as f1=inline(f); In order to use the anonymous instead of inline, I changed it to f1 = @(x)[f]; However, after declaring it like this, the code stops working correctly. I don't know what I'm doing wrong.
Thank you

回答 (1 件)

Star Strider
Star Strider 2016 年 2 月 21 日
you have to call the inline function as a function.
This works:
f = inline('cos(x) .* sin(x)');
f1 = @(x) f(x);
q = f1(pi/4);
Better is to just do:
f1 = @(x) cos(x) .* sin(x);
  4 件のコメント
Jose Trevino
Jose Trevino 2016 年 2 月 22 日
Thank you very much! I got it
Star Strider
Star Strider 2016 年 2 月 22 日
My pleasure!
If my Answer solved your problem, please Accept it.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by