Parfor when filling object vector

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 Comments

Hm, this seems to work for me using R2018a. What release of MATLAB are you using?
I am using R2017b on ubuntu.

Sign in to comment.

Answers (0)

Categories

Asked:

on 19 Jul 2018

Commented:

on 19 Jul 2018

Community Treasure Hunt

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

Start Hunting!