MATLAB: Are MATLAB user defined objects supported in PARFOR in Parallel Computing Toolbox 4.1 (R2009a)

classMATLABParallel Computing Toolboxparforudd

When I use my MATLAB user defined objects (class objects) in a PARFOR loop, I receive the following error:
Do not match the current constructor definition for class '<classname>'. The element(s) have been converted to structures.
I would like to know if MATLAB objects are supported for parallel computing when using Parallel Computing Toolbox 4.1 (R2009a).

Best Answer

MATLAB class objects are supported in parallel computing. The MATLAB class syntax prior to MATLAB 7.6 (R2008a) are also supported as well.
The specific construct of PARFOR environment requires that the MATLAB class file can be saved and loaded as a MAT file with zero arguments. This only applies to the old MATLAB class syntax.
A class system that takes multiple arguments must have a separate constructor that takes in empty arguments. This is used as a check for the MATLAB workers.
A simple implementation in an Employee class example would be of the following:
function obj = Employee(name, salary, grade)
% Handle the no-argument case
if nargin==0
name = '';
salary = 0;
grade = 0;
end
% Proceed with rest of class definition and code
obj = struct('Name', name, 'Salary', salary, ' 'Grade', grade);
obj = class(obj, 'Employee');