Function or loop to get radians

2 次查看(过去 30 天)
Hello, I am a beginner. I want to find a function or a loop to transform degrees minutes and seconds of latitud and longtitude to radians, since I have some points to work with.
Inputs: Degrees, minutes, seconds, orientation (latitude), Degrees, minutes, seconds, orientation (longitude)
Outputs: Angle in radians of latitude, angle in radians of longitude.
I want the outputs to be saved in different variables, no, let it be overwritten, so I was thinking of calling a function. How would I do this? This is what I've done:
glat=input('\nLatDegrees: ');
mlat=input('\nMin: ');
slat=input('\nSec ');
gradlat=(glat+(mlat/60)+(slat/3600));
rlat=gradlat*(pi/180);%radianslat
v=0;
while(v==0)
senlat=input('\nHemishphere (N/S): ','s');
if(strcmp(senlat,'n')||strcmp(senlat,'N'))
siglat=1;
v=1;
else
if(strcmp(senlat,'s')||strcmp(senlat,'S'))
siglat=-1;
v=1;
else
fprintf('\nWrong');
v=0;
end
end
end
gradlat=siglat*gradlat;
rlat=gradlat*(pi/180);
glong=input('\nLonDeg: ');
mlong=input('\nMin: ');
slong=input('\nSec: ');
gradlong=(glong+(mlong/60)+(slong/3600));
v=0;
while (v==0)
senlong=input('\nHemisphere (E/W): ','s');
if(strcmp(senlong,'e')||strcmp(senlong,'E'))
siglong=1;
v=1;
else
if(strcmp(senlong,'w')||strcmp(senlong,'W'))
siglong=-1;
v=1;
else
fprintf('\nWrong');
v=0;
end
end
end
gradlong=(glong+(mlong/60)+(slong/3600));
rlong=gradlong*(pi/180);%radianslong

回答(1 个)

Bhupendra Prajapati
编辑:Bhupendra Prajapati 2020-7-19
You can use
toRadians('degrees', gradlat)
to covert an angle in degrees to radian.
From more information visit the link given below ->
https://www.mathworks.com/help/map/ref/toradians.html

类别

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!

Translated by