Problems with parfor in class method
이전 댓글 표시
If I run
F=Foo(1);
F.A=pi;
F.bar();
where
classdef Foo
properties
A;
sz;
end
methods
function obj = Foo(sz)
obj.sz=sz;
end
function obj=set.A(obj,A)
if size(A)==obj.sz
obj.A=reshape(A,numel(A),[]);
end
end
function []=bar(obj)
parfor i=1:1
obj.A(1);
end
end
end
end
then I get
Error using Foo/bar (line 16)
Index exceeds matrix dimensions.
Error in test (line 4)
F.bar();
The error disappears when I replace the parfor-loop with a regular for-loop.
I get a warning in my editor on the line "if size(A)==obj.sz", saying "A set method for a non-dependent property should not access another property". However, if I make the variable "A" dependent, then I can't define a set method.
EDIT: I found out that the error also disappears when I declare "sz" first, and then "A".
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!