フィルターのクリア

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

1 回表示 (過去 30 日間)
Amirah Algethami
Amirah Algethami 2024 年 4 月 30 日
コメント済み: Karl 2024 年 5 月 1 日
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

採用された回答

Walter Roberson
Walter Roberson 2024 年 4 月 30 日
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 件のコメント
Walter Roberson
Walter Roberson 2024 年 4 月 30 日
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 2024 年 5 月 1 日
Ah, it needed to be [b; bt] rather than [b, bt]. Thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by