It takes variable number of arguments but how can i check if a particular variable argument exists like for example varargin{2}
, So far I have tried using exist
but maybe I am not using it correctly
function vatest(testindex,varargin)
if (exist('varargin{1}','var'))
disp('oneexist')
else if (exist('varargin{2}','var'))
disp('twoexist')
end
end
like for example vatest(1,2,3)
should output
twoexist
NOTE: I am already using nargin
to get the number of inputs ,but please suggest something else than that
UPDATE: Explanation for not using a nargin
lets suppose I have a test function as above
function vatest(testindex,textindex2,textindex3,varargin)
and it does some something like
if nargin >3
%%do something
if nargin >4
%%do something
if nargin >5
%%do something
if nargin >6
%%do something
if nargin >7
%%do something
if nargin >8
%%do something
and for some reason I no longer need testindex3 in the input then I have to change condition for all the if conditions
I hope it clarifies
vatest(1,2,3)
would outputoneexist
, because you check the first argument before you check the second.