开发者

read angles in radian and convert them in degrees/minutes/seconds

n=0;
d开发者_StackOverflowisp('This program performs an angle conversion');
disp('input data set to a straight line. Enter the name');
disp('of the file containing the input Lambda in radian:  ');
filename = input('   ','s');
[fid,msg] = fopen(filename,'rt');
if fid < 0
    disp(msg);
else
    A=textscan(fid, '%g',1);
    while ~feof(fid)
        Lambda = A(1);
        n = n + 1;
        A = textscan(fid, '%f',1);
    end
fclose(fid);    
end
Alpha=Lambda*180/pi;
fprintf('Angle converted from radian to degree/minutes/seconds:\n');
fprintf('Alpha      =%12d\n',Alpha);
fprintf('No of angles   =%12d\n',n);  


To convert to from deg/min/sec to degrees you use:

Degree = MinutesOfArc/(60 MinutesOfArc/Degree) +
       + SecondsOfArc/(3600 SecondsOfArc/Degree)

For instance, 45 deg, 30 min, 30 sec = 45.508 degrees. So you can invert that operation by doing:

AlphaDeg = floor(Alpha);
AlphaMinAndSec = (Alpha - AlphaDeg)*60;
AlphaMin = floor(AlphaMinAndSec);
AlphaSec = (AlphaMinAndSec - AlphaMin)*60;

Note that this doesn't work for negative inputs because of the floor operation. It's also slower than it could be. But in case your question is homework, I'll leave you to figure out the rest.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜