Hi Paul,
The second method would work, but the first one is rather confusing.
For example I tried
function varargout = test(x, y, z)
switch nargout
case {0,1} varargout = z;
case 2, varargout = { z, x };
case 3, varargout = { z, y, x };
otherwise, usage("z = test(x, y, z) or ...");
endswitch
endfunction
on three matrices, A, B, and C, of different sizes. Here is what came
out
test(A, B, C) returned ans = C
z = test(A, B, C) returned z = C
OK so far, but
[z, x] = test(A, B, C) returned
z =
{
[1,1] = C
[1,2] = A
}
and the message
error: element number 2 undefined in return list
For my application I think I just going to leave things in the order
function [x, pi, fail] = simp(A, b, c, I)
Then the function will naturally produce
a solution
a solution and the dual multiplier
a solution, the dual multiplier, and failure information
depending on nargout.
Thanks for your comments!
Regards,
Vic
At 9:31 PM -0500 12/11/03, Paul Kienzle wrote:
So write it using varargout:
function varargout = svd(A)
...
switch nargout
{0,1}, varargout = { diag(s) };
3, varargout = { u, s, v };
otherwise, usage("sigma=svd(A) or [u,s,v]=svd(A)");
end
end
or equivalently using meaningless placeholders
for the returned values:
function [r1,r2,r3] = mysvd(A)
...
if nargout<=1, r1=diag(s);
else r1=u; r2=s; r3=v; end
end
Paul Kienzle
address@hidden