Parfor when filling object vector
Ältere Kommentare anzeigen
I have an issue when using parfor loop to add values to an array of objects. Specifically:
The class definition:
classdef Point
properties
node
cp
n
curv
dx = 0;
V = 0;
T
d = 0;
adaptlevel = 0;
child = 0;
active = 0;
end
methods
function obj = Point(x,cp)
if nargin < 1
elseif nargin == 1
obj.node = x;
else
obj.node = x;
obj.cp = cp;
end
end
end
end
So, when using a parfor loop in order to fill this array of objects, like
pts(10,1) = Point;
parfor j = 1:length(pts)
pts(j).node = 1;
pts(j).cp = 1;
pts(j).n = 1;
pts(j).dx = 1;
pts(j).active = 1;
pts(j).d = 0;
end
I get
>> pts(1)
ans =
Point with properties:
node: [1×2 struct]
cp: []
n: []
curv: []
dx: 0
V: 0
T: []
d: 0
adaptlevel: 0
child: 0
active: 0
However, it works well when I use a for loop. Why? Any ideas? My goal is to find an approach to store and update values in the pts array of Objects without the need of too many conversions cell2mat, etc.
2 Kommentare
Edric Ellis
am 19 Jul. 2018
Hm, this seems to work for me using R2018a. What release of MATLAB are you using?
Argyrios
am 19 Jul. 2018
Antworten (0)
Kategorien
Mehr zu Entering Commands finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!