hi please help me, how to calculate the angle using loop
%Calculate angle
%Loop1
if azA,azB>90;
azA1=180-azA;
azB1=180-azB;
elseif azA,azB<90;
azA1=azA-0;
azB1=azB-0;
end
%Second LOOP
if azA,azB<270;
azA1=azA-180;
azB1=azB-180;
elseif azA,azB>270;
azA1=360azA;
azB1=360-azB;
end

댓글 수: 2

Dyuman Joshi
Dyuman Joshi 2021년 5월 16일
Your syntax usage is incorrect in the if and elseif statements. And this aren't loops, they are conditional statements. As for anything else, your question is unclear? What do you want to do exactly?
Thank you for mention about my mistake about using if and elseif statement. Actually, i have a 2 set of data which is azimuth A and azimuth B. i need to calculate the angle based on this 2 azimuth. I insert the azimuth A and B by using text file. Can you help me?
This in my input coding
obs = load ('obs.txt')
azA = obs(:,1);
azB = obs(:,2);

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

답변 (2개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 5월 16일

0 개 추천

If your assignment requires loop only, then here is a brief solution that can be extended a bit with some comments:
azA = input('Angle for azA: ');
azB = input('Angle for azB: ');
if azA>90 && azB>90
azA1=180-azA;
azB1=180-azB;
elseif azA<90 && azB<90
azA1=azA-0;
azB1=azB-0;
end
%% Second LOOP
if azA<270 && azB<270
azA1=azA-180;
azB1=azB-180;
elseif azA>270 &&azB>270
azA1=360-azA;
azB1=360-azB;
end
nur aida azlin abdul aziz
nur aida azlin abdul aziz 2021년 5월 16일

0 개 추천

this my solution
%Calculate Angle P
if azA>90 && azA<180
azA1=180-azA;
elseif azA>0 && azA<90
azA1=90-azA;
end
%% Second LOOP
if azB>90 && azB<180
azB1=180-azB;
elseif azB>0 && azB<90
azB1=90-azA;
end
%% Third LOOP
if azA>180 && azA<270
azA1=azA-180;
elseif azA>270 &&azA>270
azA1=azA-270;
end
%% Four LOOP
if azB>180 && azB<270
azB1=azB-180;
elseif azB>270 &&azB>270
azB1=azB-270;
end

댓글 수: 2

Walter Roberson
Walter Roberson 2021년 5월 16일
That code does not have any loops.
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 5월 16일
Note that if you have a series of values of azimuth, then you would need to build [for .. end] loop as well.

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2021년 5월 16일

댓글:

2021년 5월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by