Parallel pool: Conversion to double from cell is not possible

조회 수: 7 (최근 30일)
Light.16
Light.16 2017년 2월 6일
답변: Edric Ellis 2017년 2월 7일
Hello guys!
i'm trying to solve this problem. I started this loop (where B is a table).
parfor i=1:116676;
if G(i)== 1;
S(i,:)= table2cell(B(i,:));
end
end
My problem is that is i run the loop without "parfor" it works... but if i use "parfor" the cicle doesn't works and Matlab told me:
Conversion to double from cell is not possible.
What can i do for solve this problem?
thank you :D

답변 (1개)

Edric Ellis
Edric Ellis 2017년 2월 7일
The problem here is that you haven't pre-allocated S, and unfortunately this doesn't quite work out correctly in parfor. The simple fix is to pre-allocate S to be a cell array of the correct size.
B = table(rand(10,1), rand(10,1));
G = rand(height(B),1) > 0.5;
S = cell(height(B), width(B));
parfor i=1:height(B)
if G(i)== 1
S(i,:)= table2cell(B(i,:));
end
end

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by