the temporary variable uses a value set outside of the PARFOR loop
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
ha ha
am 13 Aug. 2018
Bearbeitet: ha ha
am 13 Aug. 2018
Let' say I have the code like this:
gcp;
a=zeros(1,3);%create the zeros matric 1x3
my_cell={[1 1 1;2 2 2],[3 3 3;4 4 4],[5 5 5;6 6 6;7 7 7]}; %this is the initial cell
parfor I=1:3
input_data=my_cell{I};%get data coordinate(x,y,z) from my_cell
[ result ] = my_function( input_data );% The result will be generated from function named "my_function". The result is kx3 matric
[a,~,~] = union(a,result,'rows');% add the result to the initial matrix a
end
In my code informed this warning: the temporary variable "a" uses a value set outside of the parfor loop. How can I fix this error for "parfor"
Thanks.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 13 Aug. 2018
You cannot do that. You are trying to use|a| as a reduction variable, but union() is not one of the supported reduction operations. You will need to do something like
my_cell={[1 1 1;2 2 2],[3 3 3;4 4 4],[5 5 5;6 6 6;7 7 7]}; %this is the initial cell
N = size(my_cell,2);
a = cell(N,1);
parfor I = 1 : N
input_data=my_cell{I};%get data coordinate(x,y,z) from my_cell
[ result ] = my_function( input_data );% The result will be generated from function named "my_function". The result is kx3 matric
a{I} = result;
end
a = unique(vertcat(a{:}), 'row');
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!