help-octave
[Top][All Lists]
Advanced

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

Re: octave and oo


From: Ernst Reissner
Subject: Re: octave and oo
Date: Sun, 14 Nov 2010 20:32:47 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.15) Gecko/20101026 SUSE/3.0.10 Thunderbird/3.0.10

On 11/14/2010 07:34 PM, John W. Eaton wrote:
> On 14-Nov-2010, Ernst Reissner wrote:
>
> | Dear John,
> | 
> | OK I tried:
> | 
> | >   function retval = DocPolynom(c)
> | >      % Construct a DocPolynom object using the coefficients supplied
> | >      if isa(c,'DocPolynom')
> | >         obj.coef = c.coef;
> | >      else
> | >         obj.coef = c(:).';
> | >      end
> | >      retval = class (obj, 'DocPolynom');
> | >   end
> | >
> | > and it should work.
> | >   
> | and it seems to bring me one step further.
> | This time i obtain:
> | 
> | octave:2> c = double(p)
> | error: no subsindex method defined for class DocPolynom
>
> It does work for me with 3.2.4 on my Debian system, using Octave from
> the Debian package.  Here is what I see:
>
>   octave3.2:1>  p = DocPolynom([1 0 -2 -5])
>   octave3.2:2> class (p)
>   ans = DocPolynom
>   octave3.2:3> double (p)
>   ans =
>
>      1   0  -2  -5
>
>   octave3.2:4> quit
>
>
> I have the following functions defined:
>
> @DocPolynom/DocPolynom.m:
>
>   function retval = DocPolynom(c)
>      % Construct a DocPolynom object using the coefficients supplied
>      if isa(c,'DocPolynom')
>         obj.coef = c.coef;
>      else
>         obj.coef = c(:).';
>      end
>      retval = class (obj, 'DocPolynom');
>   end 
>
> @DocPolynom/double.m:
>
>   function c = double(obj)
>      % DocPolynom/Double Converter
>      c = obj.coef;
>   end 
>
> | Suggestion:
> | The example is from site
> | 
> | http://www.mathworks.com/help/techdoc/matlab_oop/f3-28024.html
> | 
> | 
> | and I think it would be best to rework this site so that the examples
> | work as described.
>
> If you are saying that you think the examples on the web page should
> be changed, then I don't see how any of us here can help with that
> suggestion...
>   
hm,... the example on the web describes another kind of constructor as
you did.
So i thought, there is a mistake on the web and so i suggested to change
the documentation.
> Does the constructor without the call to class () work in Matlab?  If
> so, what version?  
It did work with octave 3.2.4 in a sense:
i could do:

octave:2> p1 = DocPolynom([1 0 -2 -5])
p1 =                                 
{                                    
  coef =                             

     1   0  -2  -5

}

and

octave:3> p2.coef(1)=15
p2 =
{
  coef =

     15    0    3    2   -7

}

but i could not invoke char(p1) or double(p1):

octave:4> char(p1)
error: octave_base_value::convert_to_str_internal (): wrong type
argument `struct'
octave:4> double(p1)
error: struct type invalid as index value


If at the end of the constructor I say "ret = class (obj, 'DocPolynom');"

octave:1> p1 = DocPolynom([1 0 -2 -5])
yields no comment: not even the feedback

p1 = 
   x^3 - 2*x -5



I am not sure: is this correct?
and

octave:2> char(p1)
ans = x^3 - 2*x - 5
octave:3> double(p1)
error: no subsindex method defined for class DocPolynom

It differs somehow from the documentation.


> I suppose it would be possiblbe to detect that a class construtor was
> called and that if it is returning a structure, not a class, to
> automatically convert the structure to a class.  But if that change
> was made in Matlab, I think it is quite recent, I was not aware of it,
> and so far, no one has reported the new incompatibility until now.  If
> this is the new behavior, then where is it documented?
>   
hm.. good question.
I am really a newbie in matlab/octave and hope i did not make nonsense..

greetings,
ernst




reply via email to

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