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 个评论
Edric Ellis
2018-7-19
Hm, this seems to work for me using R2018a. What release of MATLAB are you using?
Argyrios
2018-7-19
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!