Thread Subject: varargin{i}

Subject: varargin{i}

From: mat001

Date: 9 Feb, 2010 10:47:02

Message: 1 of 13

Can some one explain me how this function works

if ((i == eq.n1) & (j == eq.n1) & (k == eq.n1))
  switch varargin{3} % what is means ?
   case 'x'
    Aijk =
   case 'y'
    Aijk =
    case 'z'
   Aijk =
   otherwise
    error('unknown case');
  end
else
  error();
end

return

Subject: varargin{i}

From: us

Date: 9 Feb, 2010 10:54:03

Message: 2 of 13

"mat001 " <priya.biomath@gmail.com> wrote in message <hkref6$k8m$1@fred.mathworks.com>...
> Can some one explain me how this function works
>
> switch varargin{3} % what is means ?

     arg=varargin{3};
% returns in ARG the CONTENT of the 3rd CELL of the CELL array VARARGIN...
% see also
     help varargin;

us

Subject: varargin{i}

From: Parker

Date: 9 Feb, 2010 10:55:35

Message: 3 of 13

On 2月9日, 上午10时47分, "mat001 " <priya.biom...@gmail.com> wrote:
> Can some one explain me how this function works
>
> if ((i == eq.n1) & (j == eq.n1) & (k == eq.n1))
>   switch varargin{3}     % what is means ?
>    case 'x'
>     Aijk =
>    case 'y'
>     Aijk =
>     case 'z'
>    Aijk =
>    otherwise
>     error('unknown case');
>   end
> else
>   error();
> end
>
> return

check the third input parameter, if x,y,or z, assign it to Aijk,
otherwise raise error

Subject: varargin{i}

From: mat001

Date: 9 Feb, 2010 11:10:20

Message: 4 of 13

function Aijk = Prob(i, j, k, parameter, varargin)
if ((i == eq.n1) & (j == eq.n1) & (k == eq.n1))
  switch varargin{3} % what is means ?
   case 'x'
    Aijk =
   case 'y'
    Aijk =
    case 'z'
   Aijk =
   otherwise
    error('unknown case');
  end
else
  error();
end

return


Parker little more explain plz.

Subject: varargin{i}

From: mat001

Date: 9 Feb, 2010 11:12:03

Message: 5 of 13

error occurs


??? SWITCH expression must be a scalar or string constant.

Subject: varargin{i}

From: us

Date: 9 Feb, 2010 11:45:20

Message: 6 of 13

"mat001 " <priya.biomath@gmail.com> wrote in message <hkrfu3$mlf$1@fred.mathworks.com>...
> error occurs
> ??? SWITCH expression must be a scalar or string constant.

well... is that not clear enough(?)...
- correct your input arg #3...

us

Subject: varargin{i}

From: Parker

Date: 9 Feb, 2010 11:54:37

Message: 7 of 13

On 2月9日, 上午11时10分, "mat001 " <priya.biom...@gmail.com> wrote:
> function Aijk = Prob(i, j, k, parameter, varargin)
> if ((i == eq.n1) & (j == eq.n1) & (k == eq.n1))
>   switch varargin{3} % what is means ?
>    case 'x'
>     Aijk =
>    case 'y'
>     Aijk =
>     case 'z'
>    Aijk =
>    otherwise
>     error('unknown case');
>   end
> else
>   error();
> end
>
> return
>
> Parker little more explain plz.

according to the 'function Aijk = Prob(i, j, k, parameter, varargin)
' ,
varargin should be a cell array contain several elements
the switch statement will check the third element of varargin and
assign the output or raise an error based on the Value of it.

Subject: varargin{i}

From: mat001

Date: 9 Feb, 2010 12:10:22

Message: 8 of 13

Parker <xenoszh@gmail.com> wrote in message <e54d1809-c0c2-4d20-be5c-9a432d501bdc@3g2000yqn.googlegroups.com>...
> On 2月9日, 上午11时10分, "mat001 " <priya.biom...@gmail.com> wrote:
> > function Aijk = Prob(i, j, k, parameter, varargin)
> > if ((i == eq.n1) & (j == eq.n1) & (k == eq.n1))
> >   switch varargin{3} % what is means ?
> >    case 'x'
> >     Aijk =
> >    case 'y'
> >     Aijk =
> >     case 'z'
> >    Aijk =
> >    otherwise
> >     error('unknown case');
> >   end
> > else
> >   error();
> > end
> >
> > return
> >

> > Parker little more explain plz.
>
> according to the 'function Aijk = Prob(i, j, k, parameter, varargin)
> ' ,
> varargin should be a cell array contain several elements
> the switch statement will check the third element of varargin and
> assign the output or raise an error based on the Value of it.



Thanks for explanation.......
so to call this function

if I say

test1 = Prob(i, j, k, parameter, [],[],'x')

so it will give case 'x'

or if

test2 = Prob(i, j, k, parameter, [],[],'y')

so it will give case 'y'
and similarly for z

Subject: varargin{i}

From: Oleg Komarov

Date: 9 Feb, 2010 12:34:03

Message: 9 of 13

"mat001 "
> Parker
> > On 2月9日, 上午11时10分, "mat001 " <priya.biom...@gmail.com> wrote:
> > > function Aijk = Prob(i, j, k, parameter, varargin)
> > > if ((i == eq.n1) & (j == eq.n1) & (k == eq.n1))
> > >   switch varargin{3} % what is means ?
> > >    case 'x'
> > >     Aijk =
> > >    case 'y'
> > >     Aijk =
> > >     case 'z'
> > >    Aijk =
> > >    otherwise
> > >     error('unknown case');
> > >   end
> > > else
> > >   error();
> > > end
> > >
> > > return
> > >
>
> > > Parker little more explain plz.
> >
> > according to the 'function Aijk = Prob(i, j, k, parameter, varargin)
> > ' ,
> > varargin should be a cell array contain several elements
> > the switch statement will check the third element of varargin and
> > assign the output or raise an error based on the Value of it.
>
>
>
> Thanks for explanation.......
> so to call this function
>
> if I say
>
> test1 = Prob(i, j, k, parameter, [],[],'x')
>
> so it will give case 'x'
>
> or if
>
> test2 = Prob(i, j, k, parameter, [],[],'y')
>
> so it will give case 'y'
> and similarly for z

You may find useful to read the documentation about debugging.
http://www.mathworks.com/support/tech-notes/1200/1207.html

Oleg

Subject: varargin{i}

From: Parker

Date: 9 Feb, 2010 12:37:41

Message: 10 of 13

On 2月9日, 下午12时10分, "mat001 " <priya.biom...@gmail.com> wrote:
> Parker <xeno...@gmail.com> wrote in message <e54d1809-c0c2-4d20-be5c-9a432d501...@3g2000yqn.googlegroups.com>...
> > On 2月9日, 上午11时10分, "mat001 " <priya.biom...@gmail.com> wrote:
> > > function Aijk = Prob(i, j, k, parameter, varargin)
> > > if ((i == eq.n1) & (j == eq.n1) & (k == eq.n1))
> > >   switch varargin{3} % what is means ?
> > >    case 'x'
> > >     Aijk =
> > >    case 'y'
> > >     Aijk =
> > >     case 'z'
> > >    Aijk =
> > >    otherwise
> > >     error('unknown case');
> > >   end
> > > else
> > >   error();
> > > end
>
> > > return
>
> > > Parker little more explain plz.
>
> > according to the 'function Aijk = Prob(i, j, k, parameter, varargin)
> > ' ,
> > varargin should be a cell array contain several elements
> > the switch statement will check the third element of varargin and
> > assign the output or raise an error based on the Value of it.
>
> Thanks for explanation.......
> so to call this function
>
> if I say
>
> test1 = Prob(i, j, k, parameter, [],[],'x')
>
> so it will give case 'x'
>
> or if
>
> test2 =  Prob(i, j, k, parameter, [],[],'y')
>
> so it will give case 'y'
> and similarly for z

varargin is a cell array,try use { } to declare it as a cell array
like:
> test2 = Prob(i, j, k, parameter, {[],[],'y'})
=========================================
it should be OK
here is my test

function out = tryCell(i,j,k,varargin)
out = length(varargin);
switch varargin{3}
case 'x'
out = 'x';
case 'y'
out = 'y';
case 'z'
out = 'z';
otherwise
error('error');
end
end

test as
>> tryCell(1,2,3,1,2,'x')
ans =
x
>> tryCell(1,2,3,1,2,'y')
ans =
y
>> tryCell(1,2,3,1,2,'z')
ans =
z

Subject: varargin{i}

From: mat001

Date: 9 Feb, 2010 14:03:05

Message: 11 of 13

Parker <xenoszh@gmail.com> wrote in message <7a37f55f-5f5c-4d30-988f-978c36e0d904@n33g2000yqb.googlegroups.com>...
> On 2月9日, 下午12时10分, "mat001 " <priya.biom...@gmail.com> wrote:
> > Parker <xeno...@gmail.com> wrote in message <e54d1809-c0c2-4d20-be5c-9a432d501...@3g2000yqn.googlegroups.com>...
> > > On 2月9日, 上午11时10分, "mat001 " <priya.biom...@gmail.com> wrote:
> > > > function Aijk = Prob(i, j, k, parameter, varargin)
> > > > if ((i == eq.n1) & (j == eq.n1) & (k == eq.n1))
> > > >   switch varargin{3} % what is means ?
> > > >    case 'x'
> > > >     Aijk =
> > > >    case 'y'
> > > >     Aijk =
> > > >     case 'z'
> > > >    Aijk =
> > > >    otherwise
> > > >     error('unknown case');
> > > >   end
> > > > else
> > > >   error();
> > > > end
> >
> > > > return
> >
> > > > Parker little more explain plz.
> >
> > > according to the 'function Aijk = Prob(i, j, k, parameter, varargin)
> > > ' ,
> > > varargin should be a cell array contain several elements
> > > the switch statement will check the third element of varargin and
> > > assign the output or raise an error based on the Value of it.
> >
> > Thanks for explanation.......
> > so to call this function
> >
> > if I say
> >
> > test1 = Prob(i, j, k, parameter, [],[],'x')
> >
> > so it will give case 'x'
> >
> > or if
> >
> > test2 =  Prob(i, j, k, parameter, [],[],'y')
> >
> > so it will give case 'y'
> > and similarly for z
>
> varargin is a cell array,try use { } to declare it as a cell array
> like:
> > test2 = Prob(i, j, k, parameter, {[],[],'y'})
> =========================================
> it should be OK
> here is my test
>
> function out = tryCell(i,j,k,varargin)
> out = length(varargin);
> switch varargin{3}
> case 'x'
> out = 'x';
> case 'y'
> out = 'y';
> case 'z'
> out = 'z';
> otherwise
> error('error');
> end
> end
>
> test as
> >> tryCell(1,2,3,1,2,'x')
> ans =
> x
> >> tryCell(1,2,3,1,2,'y')
> ans =
> y
> >> tryCell(1,2,3,1,2,'z')
> ans =
> z



Thanks once again.

here is tryCell(1,2,3,1,2,'x')

1 23 are i j k

what is 1 2 in 1 2 'x'

Subject: varargin{i}

From: Parker

Date: 9 Feb, 2010 15:26:19

Message: 12 of 13

On 2月9日, 下午2时03分, "mat001 " <priya.biom...@gmail.com> wrote:
> Parker <xeno...@gmail.com> wrote in message <7a37f55f-5f5c-4d30-988f-978c36e0d...@n33g2000yqb.googlegroups.com>...
> > On 2月9日, 下午12时10分, "mat001 " <priya.biom...@gmail.com> wrote:
> > > Parker <xeno...@gmail.com> wrote in message <e54d1809-c0c2-4d20-be5c-9a432d501...@3g2000yqn.googlegroups.com>...
> > > > On 2月9日, 上午11时10分, "mat001 " <priya.biom...@gmail.com> wrote:
> > > > > function Aijk = Prob(i, j, k, parameter, varargin)
> > > > > if ((i == eq.n1) & (j == eq.n1) & (k == eq.n1))
> > > > >   switch varargin{3} % what is means ?
> > > > >    case 'x'
> > > > >     Aijk =
> > > > >    case 'y'
> > > > >     Aijk =
> > > > >     case 'z'
> > > > >    Aijk =
> > > > >    otherwise
> > > > >     error('unknown case');
> > > > >   end
> > > > > else
> > > > >   error();
> > > > > end
>
> > > > > return
>
> > > > > Parker little more explain plz.
>
> > > > according to the 'function Aijk = Prob(i, j, k, parameter, varargin)
> > > > ' ,
> > > > varargin should be a cell array contain several elements
> > > > the switch statement will check the third element of varargin and
> > > > assign the output or raise an error based on the Value of it.
>
> > > Thanks for explanation.......
> > > so to call this function
>
> > > if I say
>
> > > test1 = Prob(i, j, k, parameter, [],[],'x')
>
> > > so it will give case 'x'
>
> > > or if
>
> > > test2 =  Prob(i, j, k, parameter, [],[],'y')
>
> > > so it will give case 'y'
> > > and similarly for z
>
> > varargin is a cell array,try use { }  to declare it as a cell array
> > like:
> > > test2 =  Prob(i, j, k, parameter, {[],[],'y'})
> > =========================================
> > it should be OK
> > here is my test
>
> > function out = tryCell(i,j,k,varargin)
> > out = length(varargin);
> > switch varargin{3}
> >    case 'x'
> >            out = 'x';
> >    case 'y'
> >            out = 'y';
> >    case 'z'
> >            out = 'z';
> >    otherwise
> >            error('error');
> > end
> > end
>
> > test as
> > >> tryCell(1,2,3,1,2,'x')
> > ans =
> > x
> > >> tryCell(1,2,3,1,2,'y')
> > ans =
> > y
> > >> tryCell(1,2,3,1,2,'z')
> > ans =
> > z
>
> Thanks once again.
>
> here is tryCell(1,2,3,1,2,'x')
>
> 1 23 are i j k
>
> what is 1 2 in 1 2 'x'

just a test to show that,
first 1,2,3 refer to the i,j,k in tryCell(i,j,k,varargin)
then 1,2, 'x' refer to varargin

Subject: varargin{i}

From: mat001

Date: 9 Feb, 2010 15:50:20

Message: 13 of 13

Thanks

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
code us 9 Feb, 2010 05:59:06
syntax us 9 Feb, 2010 05:59:06
varargin us 9 Feb, 2010 05:59:06
cell us 9 Feb, 2010 05:59:06
rssFeed for this Thread

Contact us at files@mathworks.com