MATLAB: Matrix/Array of Objects vs. Class Constructor

arrayclassmatrixobjectooppreallocation

Let say I have a class Foo
classdef Foo
function obj = Foo(x,y)
% constructor's body
end
end
If I want to preallocate spaces for a matrix of Foo objects
>> foos = Foo(3,4);
How is it different from creating one object with arguments x = 3, y = 4?
>> foo = Foo(3,4);
Note that if I avoid preallocation, Matlab will give me some warning due to speed optimization.
Thanks,

Best Answer

Thanks for your response, Sean. However, it turns out every (nonabstract) class has a static method called empty, which can be used to create empty array. It makes things much simpler. See details here .