help-octave
[Top][All Lists]
Advanced

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

Re: empty arrays of objects


From: Jordi Gutiérrez Hermoso
Subject: Re: empty arrays of objects
Date: Mon, 20 May 2013 19:19:48 -0400

On 20 May 2013 20:04, ernst <address@hidden> wrote:
> Tell me, why does class([]) yield double?

That's just the default class, so it's also the class of the default
empty matrix.

> And why does seemingly buitlin-arrayfun not work on objects?

I'm not sure what exactly you mean here with "not work".

> And, above all, why does
>
> octave:28> a=arrayfun(@pn, [])
> a = [](0x0)
> octave:29> class(a)
> ans = double
>
> not lead to some pn-object as
> arrayfun(@pn, [1 2 3]) does?

Because the function @pn is never called since the matrix is empty.

If you create an empty array from an array that isn't empty, you'll
get an empty array of the class you want:

    x = int32(42);
    y = x(false);

Perhaps we do need a better way to create empty arrays of arbitrary
classes. I am not sure if zeros(0,0,"pn") will work for your
user-defined pn class.

- Jordi G. H.


reply via email to

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