필터 지우기
필터 지우기

how to pass inline function in a M-file function (user defined)

조회 수: 1 (최근 30일)
saloni singhal
saloni singhal 2012년 3월 26일
function out = convert(f(t),t,th)
if(th==1)
out=f(1);
return
else
out=f(th).*convert(f(t),t,th-1);
return
end
end
"in the command window"
t=[1:1:10];
f=inilne('sin(t)','t');
out=convert('f(t)','t',4);

답변 (1개)

Walter Roberson
Walter Roberson 2012년 3월 26일
function out = convert(f,t,th)
if th == 1
out = f(1);
return
else
out = f(th) .* convert(f, t, th-1);
return
end
end
In the command window,
t = [1:1:10];
f = inline('sin(t)', 't');
out = convert(f, t, 4);
Note: your convert() function never uses the value of t, so you might as well not pass it around.
I don't know why you want to be taking sin(1) ?
I am wondering if in convert(), instead of out=f(1) you want out=f(t) ?

카테고리

Help CenterFile Exchange에서 Argument Definitions에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by