I am trying to initialize an object array.
From the MATLAB documentation 1 and 2, I know that you assign the last array element to an object of the and the rest of the array should be filled with default constructed objects. e.g.
object_array(2,2) = object; % create 2 x 2 of class 'object'
I have done this in several places in my code and it has worked fine.
But I've found that for one of my classes it doesn't work.
I have an object array of objA of size 1x2x2, and I want to create an object array of objB of that size. Now objB has a constructor, and so I've made sure the constructor handles the case that the constructor has no arguments, so that the object array of objB can be default filled. e.g.
function objb = objB(parameter)
if (nargin > 0)
% do stuff with parameter
end
end
Now here's the funny part: I try to construct the objB object array using the size of objA array.
# breakpoint 1
objBArray(size(objAArray)) = objB;
# breakpoint 2
When I reach breakpoint 1,
size(objAArray) = 1, 2, 2
But when I reach breakpoint 2,
size(objAArray) = 1, 2, 2
and
size(objBArray) = 1, 2
How come objBArray isn't the same size as objAArray?
Is the problem having a constructor?