help-octave
[Top][All Lists]
Advanced

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

empty arrays of objects


From: ernst
Subject: empty arrays of objects
Date: Mon, 20 May 2013 23:57:05 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120825 Thunderbird/15.0

Hi all,
i am back to OO-programming in octave.
I have a class pn extending numbers.
So pn(1) is a constructor invocation.

i found, that arrays have the same class as their members (which I think
is very strange):

octave:32> x=1
x =  1
octave:33> class(x)
ans = double
octave:34> x=[1 2 3]
x =

   1   2   3

octave:35> class(x)
ans = double


This applies also to classes, which are not builtin:

octave:38> x=[pn(1) pn(2) pn(3)]
...
octave:39> class(x)
ans = pn

I can even apply the constructor elementwise to an array
arrayfun(@pn, [1 2 3])
...
class(ans)
ans = pn


ok, now the problem:
I found no way, to obtain an empty array of class pn.
E.g. 

octave:28> a=arrayfun(@pn, [])
a = [](0x0)
octave:29> class(a)
ans = double



I found that matlab has a function empty, for creating empty arrays of
objects.

You can imagine that i get a clash of types when trying to do oo
programming.


By the way, i also tried:

p=[pn(1)]
p(1)=[]
p =
warning: arrayfun: some elements in list of return values are undefined
[](0x0)

octave:18> class(p)
ans = pn


which works but emits a warning.. i must admit i do not understand.


Who can help???

Greetings,

Ernst



reply via email to

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