2
votes

Here is a simple example:

function [s, d] = sumdiff(a,b)    
s = a+b;
d = a-b;
%!test
%! a = [10]; b = [1];
%! assert (sumdiff (a, b), 11);

It only checks the first returned value. How to check for the second one as well?

1

1 Answers

2
votes

Usually, this is is done like so:

%!test
%! a = [10]; b = [1];
%! [s, d] = sumdiff (a, b);
%! assert (s, 11)
%! assert (d, 9)

but if you insist on having a oneliner, you can use the much less clear nthargout:

%!test
%! a = [10]; b = [1];
%! assert (nthargout ([1 2], @sumdiff, a, b), {11, 9})