Effacer les filtres
Effacer les filtres

Parallel pool: Conversion to double from cell is not possible

17 vues (au cours des 30 derniers jours)
Light.16
Light.16 le 6 Fév 2017
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

Réponses (1)

Edric Ellis
Edric Ellis le 7 Fév 2017
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

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by