error using parfor loop - Dimensions of arrays being concatenated are not consistent

10 visualizaciones (últimos 30 días)
I got the parallel toolbox to help me with this part of my code (takes weeks to compute). I am not sure where and how best to use the parfor..
I get errors like "Dimensions of arrays being concatenated are not consistent" when i implement it as below
KD=WQ';
hh=[];
HH=[];
gf=size(KD,2);
FF=length(Ped);toc;
%%
for l=1:FF
for i =1:gf
YY{i}=KD{l,i};
r=size(YY{i},1);
% U=zeros(1,length(Arc));
parfor kk=1:r
u=length(YY{i}(kk,:));
uu=YY{i}(kk,:);
Find1=[uu(1:u-1);uu(2:u)];Find1=Find1';
[C,ia,ib] = intersect(Arc,Find1,'rows');
U(ia)=1;
HH=[HH;U];
hh=[hh;length(Find1)-1];
U=zeros(1,length(Arc));
end
end
end

Respuestas (1)

Lokesh
Lokesh el 4 de Nov. de 2024 a las 4:14
Hello red,
In a 'parfor' loop, temporary variables are cleared at the beginning of each iteration.
In your code, the variable 'U' is cleared at the start of each iteration, leading to issues. To resolve this, ensure that 'U' is initialized before it is used.
Refer to the following code for guidance:
parfor kk = 1:r
u = length(YY{i}(kk, :));
uu = YY{i}(kk, :);
Find1 = [uu(1:u-1); uu(2:u)];
Find1 = Find1';
[C, ia, ib] = intersect(Arc, Find1, 'rows');
U = zeros(1, length(Arc)); % Initialize U here
U(ia) = 1;
HH = [HH; U];
hh = [hh; length(Find1) - 1];
end
For more information, please refer to the documentation on Temporary variables in 'parfor':
  1 comentario
Walter Roberson
Walter Roberson el 4 de Nov. de 2024 a las 4:25
Also, I would recommend
uu = YY{i}(kk, :);
Find1 = [uu(1:end-1); uu(2:end)].';
[C, ia, ib] = intersect(Arc, Find1, 'rows');
U = zeros(1, length(Arc)); % Initialize U here
U(ia) = 1;
HH = [HH; U];
hh = [hh; size(Find1,2)];
I have to wonder whether Find1 is being constructed properly; it is currently being constructed as a single row.

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by