Parallel pool: Conversion to double from cell is not possible

7 次查看(过去 30 天)
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