n=0;
disp('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);
views:
150answers:
1
+4
A:
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.
mtrw
2010-05-05 07:15:10
+1 for "the rest is left to the student for an exercise."
Marc
2010-05-05 12:22:49