loop results on the same result

Hello, I'm trying to calculate a variable with in a loop, yet the loop always result on the same value, I've done the calculations on a paper and they shouldn't be equal. here's the loop code:
for i=1:1
alpha_g(i)= -((z1(i)./((ki_2(j))-1))+(z2(i)./((ki_1(j))-1)));
for j=1:6
alpha_g(j)= -((z1(i)./((ki_2(j))-1))+(z2(i)./((ki_1(j))-1)));
end
end

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 2 月 14 日

0 投票

Your outer loop use j before it is defined. After the inner loop, j is left at the last thing it was assigned, so it will be 6. And that is what is used in the next iteration of the for i loop.
Also, you are writing to the same variable in both loops.

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2022 年 2 月 14 日

回答済み:

2022 年 2 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by