Filter löschen
Filter löschen

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

32 Ansichten (letzte 30 Tage)
Andrew Lackey
Andrew Lackey am 26 Sep. 2021
Beantwortet: the cyclist am 26 Sep. 2021
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>>

Antworten (1)

the cyclist
the cyclist am 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

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by