|
There is another method, but only if class1 is not an abstract method:
a = class1; %initialize array as a class1-array
a(1) = []; %make it emtpy again, not necessary
a(1) = subclass1;
a(2) = subclass2;
My big question is now, how do I do this if class1 is an abstract class?
The reason I don't want to use cell arrays is that it is programmatically not nice and anything could be stored in that array, whereas in the other method, just class1 based objects are allowed.
Thanks,
Axel
"Michal " <mjama@ksu.edu> wrote in message <gfj3k5$jcs$1@fred.mathworks.com>...
> Yes, making 'a' a cell array solves the problem!
> Thanks!
>
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <0aacb328-2f15-40de-a6f4-7e6fd7c72f8d@u29g2000pro.googlegroups.com>...
> > On Nov 13, 10:20=A0pm, "Michal " <mj...@ksu.edu> wrote:
> > > Hi,
> > >
> > > I want to create an array of objects. The objects are derived from the sa=
> > me superclass, e.g.
> > > classdef class1
> > > =A0 ...
> > > end
> > >
> > > classdef subclass1 < class1
> > > ...
> > > end
> > > classdef subclass2 < class1
> > > ...
> > > end
> > >
> > > >> a(1) =3D subclass1();
> > > >> a(2) =3D subclass2();
> > >
> > > Error....
> > >
> > > Is it possible to have array like that at all?
> > > Thanks,
> > > Michal
> >
> > Wouldn't "a" need to be a cell array?
|