Parfor+for+if+if How to calculate variable form last if

1 vue (au cours des 30 derniers jours)
Amirah Algethami
Amirah Algethami le 30 Avr 2024
Commenté : Karl le 1 Mai 2024
See my code
parfor i = 1:n
for j=1:m
if some_condition(i)
if some_condition(i)
t=do_something(i);
b = [b;t];
end
end
end...
end
I want all b values to get out from the par

Réponse acceptée

Walter Roberson
Walter Roberson le 30 Avr 2024
b = [];
parfor i = 1:n
bt = [];
for j=1:m
if some_condition(i)
if some_condition(i)
t=do_something(i);
bt = [bt;t];
end
end
end...
b = [b, bt];
end
  5 commentaires
Walter Roberson
Walter Roberson le 30 Avr 2024
m = 7;
n = 3;
b = [];
parfor i = 1:n
bt = [];
for j=1:m
if rand > 0.5
if rand > 0.5
t=i;
bt = [bt;t];
end
end
end
b = [b; bt];
end
b
b = 7x1
1 1 2 2 3 3 3
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Karl
Karl le 1 Mai 2024
Ah, it needed to be [b; bt] rather than [b, bt]. Thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Parallel for-Loops (parfor) dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by