Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
saloni singhal
saloni singhal el 26 de Mzo. de 2012
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);

Respuestas (1)

Walter Roberson
Walter Roberson el 26 de Mzo. de 2012
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) ?

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by