colon operation (:) causes parfor to fail on cell array
이전 댓글 표시
The following code causes Matlab to throw subscript assignment error:
s=cell(1,20);
parfor i = 1:20
s{:,i}=1;
end
However, when the colon operator is replaced with a 1, there is no error:
s=cell(1,20);
parfor i = 1:20
s{1,i}=1;
end
My guess is this involves a slicing issue somehow. Any insights?
댓글 수: 1
Sergio Santos
2015년 2월 16일
There is a solution to this. Reshaping whatever you want to send to parfor and turning it into a single column or raw vector. Also make a vector to store the length of each vector you reshape. Then when the operation is finished reshape back into matrix form. Shaping and reshaping is very fast and can be fastly done by a single worker, i.e. no need parallel computing.
채택된 답변
추가 답변 (2개)
It has a priori nothing to do with PARFOR; the expression involving the colon on the left hand side is a comma separated list (CSL), so you cannot have the scalar 1 on the right hand side. Try it with a simple FOR loop and there will be no difference.
I don't know exactly what you want to do with that, but I guess that it is something like
s(:,i) = {1} ;
댓글 수: 7
Jan
2013년 3월 28일
It is at least strange, that the comma-separated list on the left side with only 1 element differs from s{1,i}.
I don't find it too strange in the sense that the compiler must check whether the operation is legal type/structure-wise and not whether an illegal operation (type/structure-wise) could still be performed because a singleton dimension is involved and there is therefore no ambiguity.
Marshall
2013년 3월 29일
Hmm, you're right; yesterday I made a quick test on a distant machine before answering, which failed with the simple FOR loop, but I probably made a mistake because it's working on my laptop now (not the same setup though, so I should retry on the distant machine when I have time).
I would definitely be interested in the answer to this question then. It might be worth asking Mathworks directly if you get now clear answer here.
Marshall
2013년 3월 29일
Cedric
2013년 3월 29일
Thank you for the update! I will think about it a bit more about it and perform a few tests on my side.
Marshall
2013년 3월 29일
Ben
2013년 4월 12일
0 개 추천
please tell us they working on a patch. i've come across this bug too now in 2013a
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!