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

26 views (last 30 days)
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>>

Answers (1)

the cyclist
the cyclist on 26 Sep 2021
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

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!