MATLAB: Transforming an m-file to an anonymous or inline function

function

Hi, I have the following function
function out=myfun(x,y,z)
aa=h1(x,y,z);
dd=h2(x,y,z);
out=[x(1)+y(2)
x(3)+z(2)
x(1)+aa
x(3)+dd*y(1)];
Is there any way I can write this function either as inline or anonymous? that is without writing an m-file?
Thanks, J.

Best Answer

You need to get rid of the temp variables aa and dd:
aa = @(x,y,z)(h1(x,y,z));
dd = @(x,y,z)(h1(x,y,z));
fcn = @(x,y,z)([x(1)+y(2); x(3)+z(2); x(1)+aa(x,y,z); x(3)+dd(x,y,z)*y(1)]);