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: varargin (no name list) vs. if (has name list)
Replies: 3   Last Post: Aug 2, 2013 10:02 AM

Advanced Search

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

Posts: 336
Registered: 4/17/07
varargin (no name list) vs. if (has name list)
Posted: Aug 1, 2013 9:59 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi

if one uses varargin, like
function varlist2(X,Y,varargin)
one doesn't know what name the varargin really is.

I try:
function varlist2(X,Y)
fprintf('%d \n',X);
if(isequal(X,2))
fprintf('%d \n',Y);
end
end
then
>> varlist2(1)
1
>> varlist2(2)
2
??? Input argument "Y" is undefined.

Error in ==> varlist2 at 4
fprintf('%d \n',Y);

>> varlist2(2,5)
2
5

It works and also has varargin: Y and also have a good name.
Isn't this better?

Mike



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.