# how to increase two variables in a for loop at the same time

조회 수: 3 (최근 30일)
Ali Deniz . 2022년 4월 28일
댓글: Voss . 2022년 4월 29일
for theta_inf_1 = 7:2:15
for theta_inf_2 = 15:-2:7
end
end
How can I increase these loops at the same time. I mean when the theta_inf_1 = 7, theta_inf_2 = 15, and also when theta_inf_1 = 9, theta_inf_2=13. Thank you.

댓글을 달려면 로그인하십시오.

### 채택된 답변

Voss 2022년 4월 28일
In general:
theta_inf_1_values = 7:2:15;
theta_inf_2_values = 15:-2:7;
for ii = 1:numel(theta_inf_2_values)
disp(ii)
theta_inf_1 = theta_inf_1_values(ii)
theta_inf_2 = theta_inf_2_values(ii)
% the rest of your loop
end
1
theta_inf_1 = 7
theta_inf_2 = 15
2
theta_inf_1 = 9
theta_inf_2 = 13
3
theta_inf_1 = 11
theta_inf_2 = 11
4
theta_inf_1 = 13
theta_inf_2 = 9
5
theta_inf_1 = 15
theta_inf_2 = 7
(In this particular case, theta_inf_1 == 22-theta_inf_2 so you could use that relation instead.)
##### 댓글 수: 2표시 이전 댓글 수: 1숨기기 이전 댓글 수: 1
Voss 2022년 4월 29일
You're welcome!

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!