MATLAB: Is assignment to a cell array of objects class property slow in MATLAB 7.6 (R2008a)

MATLABmcosoopperformancespeed

I have a simple class "baseClass" and a class "cellClass" with a property that is a cell array of objects of "baseClass"
classdef cellClass < handle
properties
basecell = cell(1,1000);
end
methods
function obj = createCell(obj)
for i = 1:1000
newbase = baseClass(4,5,6);
obj.basecell{i} = newbase;
end
end
end
end
From profiling my code, I find that the assignment of objects of "baseClass" to the elements of the cell array is prohibitively slow, (taking around 20 seconds for 1000 assignments)

Best Answer

This bug has been fixed in Release 2011a (R2011a). For previous product releases, read below for any possible workarounds:
When the variable used to aggregate objects is a property of the current object, there are a number of permissions checks and bookkeeping that needs to be done, resulting in the reported performance decrease in MATLAB 7.6 (R2008a).
As a workaround, use a local variable within the loop to create the array of objects and assign it to the property at the end of the loop. This will minimize the number of checks required and should greatly improve performance. For example,
classdef cellClass < handle
properties
basecell = cell(1,1000);
end
methods
function obj = createCellFast(obj)
for i = 1:1000
newbase = baseClass(4,5,6);
basecell{i} = newbase;
end
obj.basecell = basecell;
end
end
end