How I can add For loop inside of if statement ?
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello everyone! Kindly ask how I can make for loop inside of if statement. If it is allowed to do in that order.
for example I want to set an angle that was calculated according to the if statement and the calculated angle will be set for the next iteration of for loop. My main code is running, and I got an answer that the angle was calculated two times and two values changed for one iteration. But it should be like the result of first calculation set as Theta for the next iteration, and in the second iteration it calculates according to the previous one.
Thank you in advance
This is my code
k = 5;
if Xr == 0
planes(:,:,1)
for i = 1:K
ThetaB = 90 - Theta0;
PhiB = Phi0;
fprintf('ThetaB: %f\n',ThetaB);
end
elseif Xr == 3
planes(:,:,3)
for i = 1:k
ThetaB = 90-Theta0;
PhiB = Phi0;
fprintf('ThetaB: %f\n',ThetaB);
end
elseif Yr == 0
planes(:,:,2)
ThetaB = 90-Theta0;
PhiB = Phi0;
fprintf('ThetaB: %f\n',ThetaB);
elseif Yr == 3
planes(:,:,4)
for i = 1:k
ThetaB = 90 - Theta0;
fprintf('ThetaB: %f\n',ThetaB);
end
elseif Zr == 0
planes(:,:,5)
for i = 1:k
ThetaB = Theta0;
PhiB = Phi0;
fprintf('ThetaB: %f\n',ThetaB);
end
elseif Zr == 3
planes(:,:,6)
for i = 1:k
ThetaB = Theta0;
PhiB = Phi0;
fprintf('ThetaB: %f\n',ThetaB);
end
end
And this is how I am running my main
for ii = 1:K
ii
X(ii)
Y(ii)
Z(ii)
Theta(ii)
댓글 수: 4
Jan
2023년 3월 14일
What does "plane number is odd" mean? Which variable represents the "plane number"?
What are the functions reflection5 and planeLocation5?
"And it seems like my angle ThetBar calculated two times per iteration which lead to the mistake" - Why fo you think so?
답변 (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!