how to pass inline function in a M-file function (user defined)
조회 수: 3 (최근 30일)
이전 댓글 표시
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);
댓글 수: 0
답변 (1개)
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) ?
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Argument Definitions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!