Dear All,
I would like to find a functional way to access outputs of functions with multiple outputs. Assume I have a function "twout" defined in a m-file as follows
function [foo, bar] = twout(x, y) foo = x+y; bar = x-y;end
I would like now to access the SECOND output "bar" from a function handle, i.e. I am looking for a function (or something which can be put into an anonymous function) called "somemagic" say, such that an anonymous function can be defined as
anoneout = @(x,y)( somemagic( twout(x, y) )
and the call
@anoneout(1,2)
produces -1.
It is clear that I can always
- write anoneout into a separate .m-file where I make a proper call to twout
- switch "foo" and "bar" in the function definition.
- return a structured data type instead of 2 outputs
My question is really whether these workaroounds are indeed the only solutions.
Thanks
gg
Best Answer