MATLAB: How to initialize an object array as a class property

initializationobject arrayoop

Here are two code snippets illustrating my problem:
classdef SomeClass
properties
foo;
bar;
end
end
and in another file:
classdef SomeOtherClass
properties
%Array of SomeClass objects.
someClassArray;
end
methods
function obj = SomeOtherClass(n)
%Initialize the array, as n can be large.
obj.someClassArray(n,1) = SomeClass();
end
end
end
When initializing an object of the second class, Matlab assusmes the someClassArray property is a double, and gives an error:
The following error occurred converting from SomeClass to double:
Conversion to double from SomeClass is not possible.
Error in SomeOtherClass (line 10)
obj.someClassArray(n,1) = SomeClass();
How do I get around this?

Best Answer

      methods
         function obj = SomeOtherClass(n)
               tmp(n,1)=someClass;
              obj.someClassArray=tmp;
          end
      end