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

3 次查看(过去 30 天)
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).

采纳的回答

MathWorks Support Team
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');

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息

产品


版本

R2009a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by