How to change variable value for every iteration in a for loop?

26 ビュー (過去 30 日間)
Andrew Lackey
Andrew Lackey 2021 年 9 月 26 日
回答済み: the cyclist 2021 年 9 月 26 日
I have an equation within a for loop that uses multiple variables. All of the variables (except for variable a) are given in a txt file.
I want variable a to change in value after every loop in this for loop:
a = 5, 10, 15, 20, 25
length of x is 200
%Txt file data
f = data(:,1); %Length is 200
z = data(:,2); %Length is 200
x = data(:,3); %Length is 200
a = [5; 10; 15; 20; 25]
for n=1:length(x)
l(n) = f(n).*(a)-((z(n)).*(a));
end
Mathematically, it would look like this:
l(n) = f(n)*(5) - (z(n)*(5)) <<For 200 iterations>>
then it would loop to the next a value:
l(n) = f(n)*(10) - (z(n)*(10)) <<For 200 iterations>>
then it would loop to the next a value:
l(n) = f(n)*(15) - (z(n)*(15)) <<For 200 iterations>>

回答 (1 件)

the cyclist
the cyclist 2021 年 9 月 26 日
for na = 1:length(a)
for n=1:length(x)
%Coefficient of Lift at each panel
l(n) = f(n).*(a(na))-((z(n)).*(a(na)));
end
end

カテゴリ

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