two for loops in parallel

1 回表示 (過去 30 日間)
Dharma Khatiwada
Dharma Khatiwada 2022 年 8 月 16 日
コメント済み: Dharma Khatiwada 2022 年 8 月 16 日
Hello everyone,
I am trying to run two parallel 'for loops' in the following code if possible. I want to add 0.5 to M (upto the length of vector A i.e. 6) everytime with new value of j.
Thanks
Dharma
M=5;
x=0;
A=[1 4 7 10 13 16 19];
for j=A
x=x+M*j;% I am trying to add 0.5 to M everytime j picks a new number.
% for example, x=x+5*1, x=x+(5+0.5)*4, x=x+(5.5+0.5)*7 and so on
end

採用された回答

the cyclist
the cyclist 2022 年 8 月 16 日
If I understand you correctly, you don't need two for loops, and this will do what you want
M=5;
x=0;
A=[1 4 7 10 13 16 19];
for j=A
x=x+M*j;
M=M+0.5;
end
  1 件のコメント
Dharma Khatiwada
Dharma Khatiwada 2022 年 8 月 16 日
Yes. Thank you!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by