Arrays of user objects



I've created a fairly simple class and can instantiate and work with
objects of the class. Now someone has asked for the ability to
create arrays of objects, which I thought would be straight-forward,
but I'm getting errors from the subsref.m function.

I don't understand why subsref is being called. I'm attempting to
create an array as follows:

obj1 = myClass(args);
obj2 = myClass(args);
objArray = [obj1,obj2];

If I then ask for objArray(1), I get subsref errors, because the
objArray is of type myClass.

I thought subsref was for handling index references INTO an object,
e.g. obj1(1), whereas this is a case where I want to index into an
array and get a myClass object as a return value.

What am I misunderstanding? Is there a way to assign objArray =
[obj1,obj2];?

thanks,
Bruce
.



Relevant Pages

  • Re: Why does SUBSREF of my own class crash?
    ... day I try to access object field using dot notation. ... I run into problem with an array of two ... What is going on here is that MATLAB allows you to write a subsref method that imitates MATLAB's behavior on ordinary structs, ...
    (comp.soft-sys.matlab)
  • Re: Arrays of user objects
    ... I don't understand why subsref is being called. ... array and get a myClass object as a return value. ... If you overload subsref you can change the meaning of objArrayto ... If you want the built in array indexing to ...
    (comp.soft-sys.matlab)
  • Re: Arrays of user objects
    ... I don't understand why subsref is being called. ... objArray is of type myClass. ... I thought subsref was for handling index references INTO an object, ... array and get a myClass object as a return value. ...
    (comp.soft-sys.matlab)
  • How do i initialize an array using Reflection
    ... I have a class (type - MyClass). ... class and then create an array of type MyClass and intialize this ... array with the instance. ...
    (microsoft.public.dotnet.framework)