From: Ilkka Pohjalainen on 30 Jun 2010 15:55 Let's say that I have a function myFun with multiple output arguments. function [A,B,C,D,E,F] = myFun(inputArg) .... end I want to have only the last argument of the output arguments without actually assigning the rest of the arguments. Nowadays I just use the following: [dummy, dummy, dummy, dummy, dummy, F] = myFun(arg); But I would like to use something like: [,,,,,F]=myFun(arg); So how to take an arbitraty output argument(s) of all output arguments without assigning values to those that I don't want?
From: Andy on 30 Jun 2010 16:03 "Ilkka Pohjalainen" <ip.quant(a)gmail.com> wrote in message <i0g7ep$fkv$1(a)fred.mathworks.com>... > Let's say that I have a function myFun with multiple output arguments. > > function [A,B,C,D,E,F] = myFun(inputArg) > ... > end > > I want to have only the last argument of the output arguments without actually assigning the rest of the arguments. > > Nowadays I just use the following: > [dummy, dummy, dummy, dummy, dummy, F] = myFun(arg); > > But I would like to use something like: > [,,,,,F]=myFun(arg); > > So how to take an arbitraty output argument(s) of all output arguments without assigning values to those that I don't want? My version of MATLAB is not the most recent, but I believe the syntax for this is: [~,~,~,~,~,F] = myFun(arg);
From: dpb on 30 Jun 2010 16:08 Ilkka Pohjalainen wrote: > Let's say that I have a function myFun with multiple output arguments. > > function [A,B,C,D,E,F] = myFun(inputArg) > ... > end > > I want to have only the last argument of the output arguments without > actually assigning the rest of the arguments. > Nowadays I just use the following: > [dummy, dummy, dummy, dummy, dummy, F] = myFun(arg); > > But I would like to use something like: > [,,,,,F]=myFun(arg); > > So how to take an arbitraty output argument(s) of all output arguments > without assigning values to those that I don't want? [~,~,~,~,~,F]=myFun(arg); Not sure which version introduced it... --
From: Ilkka Pohjalainen on 30 Jun 2010 17:40 dpb <none(a)non.net> wrote in message <i0g8c1$2jm$1(a)news.eternal-september.org>... > > [~,~,~,~,~,F]=myFun(arg); > > Not sure which version introduced it... > MATLAB Version 7.9 (R2009b) introduced it. I'm running R2008b. So neat looking workarounds are appreciated.
From: James Tursa on 30 Jun 2010 18:03
"Ilkka Pohjalainen" <ip.quant(a)gmail.com> wrote in message <i0gdk4$rtm$1(a)fred.mathworks.com>... > dpb <none(a)non.net> wrote in message <i0g8c1$2jm$1(a)news.eternal-september.org>... > > > > [~,~,~,~,~,F]=myFun(arg); > > > > Not sure which version introduced it... > > > > MATLAB Version 7.9 (R2009b) introduced it. I'm running R2008b. > > So neat looking workarounds are appreciated. I think you are stuck with [dummy, dummy, dummy, dummy, dummy, F] = myFun(arg); clear dummy Note that this does exactly the same thing as the new syntax [~,~,~,~,~,F]=myFun(arg); So I don't see a big deal here. In both cases all of the actual return arguments are still created and returned by myFun and then the unwanted ones are cleared from memory. There is no memory or execution time savings of one method vs the other method. So using dummy isn't really all that bad, other than looks. James Tursa |