I have a handle-based class that I need to create a vector of. An easy method of doing this is to dynamically construct the vector in a for loop, but this causes mlint to complain about the changing vector size.
classdef HandleClass < handle
...
end
...
for i = 1:10
foo(i) = HandleClass();
end
I'm suspicious of the resource-hit required to use this method to allocate large arrays of complicated objects.
A comment in a previous thread described a useful method to create a vector using the repmat function. However, @gnovice warned that doing that would create a vector of handles pointing to the same object. I have tested this and it appears to be the case.
Is there a trick that allows a vector of unique handle objects to be pre-allocated without the use of a for loop?
Solution Summary
The solution presented by SCFrench correctly allocates the memory for the creation of a vector of objects. Other solutions will create the vector, but will not allocate the memory.
foo(10) = HandleClass();