I need some help with the quad() function in MATLAB. I've simplified my issue to make the following code (and thus my problem) easier to understand. function testint clc; %%% Formula x = 0:0.001:pi; x = [zeros(1,40) x zeros(1,40)]; y = sin(x); Result = quad(@work, min(x), max(x)) end function [a b c q y s] = work(x) a = log(x); b = cos(x); c = 5.*x; q = 2.^x; y = sin(x); s = 2./x; end The value of "Result" always gives me the first output of work(x) (i.e., a). I need "Result" to give me the value of y (the 5th output of work(x)). How can I manipulate the function handle and/or call to work(x) to get this? Also, I am using work(x) in other locations, so I cannot manipulate the inputs / outputs (or even the order... such as, if I move y to the beginning (i.e., function [y a b c q s] = work(x) ... end) it works perfectly). Thanks for any suggestions!