help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

using setfield with an object (getting an error)


From: Carnë Draug
Subject: using setfield with an object (getting an error)
Date: Sun, 2 Oct 2011 15:50:14 +0100

Hi,

I get the following error when using setfield to set the value of one
of the fields if the structure is an object (I actually get the first
2 lines repeated many times before getting the last error)

error:   
/home/octave-admin/bin-octave-3.4.2/share/octave/3.4.2/m/miscellaneous/setfield.m
at line 57, column 9
error:   
/home/carandraug/development/octave-forge/main/general/inst/@inputParser/subsasgn.m
at line 33, column 13
error: assignment failed, or no method for `class = scalar'

Here's the context. I'm setting up a class (inputParser) and I'm using
subsasgn to set some of its properties (CaseSensitive for example). As
such, I have the following in subsasgn (inPar is the object with class
inputParser):

----------------
function inPar = subsasgn (inPar, idx, rhs)
 if ( idx.type != '.' )
   error ("invalid index for class %s", class (inPar) );
 endif
 switch idx.subs
   case {'CaseSensitive', 'FunctionName', 'KeepUnmatched', 'StructExpand'}
     inPar = setfield (inPar, idx.subs, rhs); ## this is the line
that causes the problem
   otherwise
     error ("invalid index for assignment of class %s", class (inPar) );
 endswitch
endfunction
----------------

which causes the error mentioned above when I do something such as
'obj.CaseSensitive = 1'

The problem seems to be caused by using the object in setfield since
replacing idx.subs by a string does not fix the problem.

I can work around easily this by having a separate case block for each
of them (that works fine) and assign the value with
'inPar.CaseSensitive = rhs' but that doesn't look right, repeated
code. How can I do this with setfield or someother function?

Thank in advance,
Carnẽ Draug


reply via email to

[Prev in Thread] Current Thread [Next in Thread]