How to change variable value for every iteration in a for loop?
29 次查看(过去 30 天)
显示 更早的评论
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>>
0 个评论
回答(1 个)
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!