Roman wrote:
> Is there a way in MATLAB to get a list of function
> arguments (both input and output) as declared in M-file?
>
> I.e. given a function
> function [out1, out2] = foo(in1, in2, in3)
> defined in the foo.m file I'm interested in something like
>
> [input_arg_list, output_arg_list] = fetch_arg_list('foo.m');
>
> Which would return
> input_arg_list = {'in1', 'in2', 'in3'};
> outpuy_arg_list = {'out1', 'out2'};
>
> Thank you,
> Roman
>
>
>
>
no. you could do it yourself though quite easily. but what are you going
to do in the many cases where varargin and varargout are used? or where
default arguments are provided in the code? and what would be the use of
such a fragile thing be anyways?
Michael Wild <themiwi.REMOVE.THIS@student.ethz.ch> wrote in
message <46b9be5c$1@news1-rz-ap.ethz.ch>...
> Roman wrote:
> > Is there a way in MATLAB to get a list of function
> > arguments (both input and output) as declared in M-file?
> >
> > I.e. given a function
> > function [out1, out2] = foo(in1, in2, in3)
> > defined in the foo.m file I'm interested in something
like
> >
> > [input_arg_list, output_arg_list] = fetch_arg_list
('foo.m');
> >
> > Which would return
> > input_arg_list = {'in1', 'in2', 'in3'};
> > outpuy_arg_list = {'out1', 'out2'};
> >
> > Thank you,
> > Roman
> >
> >
> >
> >
>
> no. you could do it yourself though quite easily. but
what are you going
> to do in the many cases where varargin and varargout are
used? or where
> default arguments are provided in the code? and what
would be the use of
> such a fragile thing be anyways?
>
>
> michael
Hi,
I need this for some dynamic framework that would call
functions of certain type (no vararg-s) automatically using
'eval'. In order to compose the correct calling string for
the 'eval' I need to know the list of input and output
arguments to the function.
This is not a general purpose solution - just an automation
trick to make things easier for me.
By the way, do you know an easy and elegant way to parse
MATLAB source to fetch these?
"us " <us@neurol.unizh.ch> wrote in message
<f9ct7p$qko$1@fred.mathworks.com>...
> Roman:
> <SNIP looking for a peek preview...
>
> > input_arg_list = {'in1', 'in2', 'in3'};
> > outpuy_arg_list = {'out1', 'out2'};
>
> a hint:
>
> % this is getting close
> help nargin;
> help nargout;
> % eg,
> nargin('unique')
> % ans = 3
> nargout('unique')
> % ans = 3
>
> us
>
nargin and nargout are good if you used them INSIDE the
function.
I'm talking about getting the argument list OUTSIDE the
function (without calling it).
"us " <us@neurol.unizh.ch> wrote in message
<f9cvar$hak$1@fred.mathworks.com>...
> Roman:
> <SNIP does not read replies properly...
>
> > nargin and nargout are good if you used them INSIDE the
> function...
>
> you are so wrong - and obviously did not try the examples
> that were shown... nor did you bother to read the help as
> suggested...
>
> % at the command prompt, type
> nargin('unique')
>
> us
yes, you're right - nargin can indeed return the number of
arguments.
Still, I'm interested in the list of input and output
arguments.
> yes, you're right - nargin can indeed return the number of
> arguments.
> Still, I'm interested in the list of input and output
> arguments.
For plot-related functions (plot, line, bar, scatter etc.),
you can use the following highly-undocumented method
(substitute 'bar' by your function name):
args =
cell(com.mathworks.mlwidgets.graphics.PlotMetadata.getPlotSignature('bar').getArgs);
for argsIdx = 1 : length(args)
axis = args{argsIdx}.getAxis;
name = args{argsIdx}.getName;
label = args{argsIdx}.getLabel;
dims = args{argsIdx}.getNumDimensions;
reqObj = args{argsIdx}.getRequired;
requiredFlag = reqObj.equals(reqObj.REQUIRED);
end
type the following to see the full list of supported
functions for the above:
com.mathworks.mlwidgets.graphics.PlotMetadata.listAllSignatures;
> > I'm interested in the list of input and output
> arguments...
>
> well, then i guess you'll be interested in my utility
> <farg>, which i will upload to the FEX...
> it should be available in 1-2 days...
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.