Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Varargout "the other way around"?
Replies: 2   Last Post: Oct 1, 2013 10:08 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Niels

Posts: 6
Registered: 4/10/13
Varargout "the other way around"?
Posted: Oct 1, 2013 4:51 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

I am trying to write a function where the number of output arguments depends on the value of one of my input arguments. However, I cannot specify upfront what the output of my function will be in a regular way.

Basically I'm looking for a way to use varargout in the script itself instead of in my function, so that I do not have to specify my output explicitly, but where I do get all the variables that are defined in my function. Putting all the output arguments in cells is not really an option, as I really need the variables explicitly named without the need to find a string in a cell.

Is this possible? :)


Small example:

runFile.m
------------
% define In1 and In2
[Out1,output] = SomeFunction(In1,In2) % the number of output arguments is variable
% do some more things
------------

SomeFunction.m
------------
function [Out1,varargout]=SomeFunction(In1,In2)
Out1 = 1;
switch In2
case {'A' 'B'}, % ...5 output arguments...
case {'C'}, % ...8 output arguments...
end
end
------------



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.