필터 지우기
필터 지우기

Anonymus Function from Input function

조회 수: 4 (최근 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 CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by