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!