Prev: Enumeration
Next: Radon Transform
From: us on 9 Feb 2010 06:45 "mat001 " <priya.biomath(a)gmail.com> wrote in message <hkrfu3$mlf$1(a)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
From: Parker on 9 Feb 2010 06:54 On 2æ9æ¥, ä¸å11æ¶10å, "mat001 " <priya.biom...(a)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.
From: mat001 on 9 Feb 2010 07:10 Parker <xenoszh(a)gmail.com> wrote in message <e54d1809-c0c2-4d20-be5c-9a432d501bdc(a)3g2000yqn.googlegroups.com>... > On 2月9日, 上午11时10分, "mat001 " <priya.biom...(a)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
From: Oleg Komarov on 9 Feb 2010 07:34 "mat001 " > Parker > > On 2月9日, 上午11时10分, "mat001 " <priya.biom...(a)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
From: Parker on 9 Feb 2010 07:37
On 2æ9æ¥, ä¸å12æ¶10å, "mat001 " <priya.biom...(a)gmail.com> wrote: > Parker <xeno...(a)gmail.com> wrote in message <e54d1809-c0c2-4d20-be5c-9a432d501...(a)3g2000yqn.googlegroups.com>... > > On 2月9日, 上午11时10分, "mat001 " <priya.biom...(a)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 |