Are MATLAB user defined objects supported in PARFOR in Parallel Computing Toolbox 4.1 (R2009a)?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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).
Respuesta aceptada
MathWorks Support Team
el 31 de Jul. de 2009
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!