function main disp('main function') a = 1; nested(2) function z = nested(x) disp('nested') z = a+x; quad(@(q) nested2(q,a),z,1) function y = nested2(x,a) disp('nested2') % here it does not work y = a.*sin(x); end end end % function y = nested2(x,a) %% here it works % disp('nested2') % y = a.*sin(x); % end