2010-05-05 88 views
0
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); 
+0

這是什麼?請格式化.. – SysAdmin 2010-05-05 04:43:00

+3

這裏有什麼問題? – Jonas 2010-05-05 04:52:27

+1

需要家庭作業標籤嗎? – 2010-05-05 05:45:50

回答

4

要轉換到從度/分鐘/秒至使用度:

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

例如,45度,30分鐘,30秒= 45.508度。所以,你可以通過做反轉該操作:

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

請注意,這不適合,因爲floor操作的負輸入工作。它也比它慢。但如果你的問題是作業,我會讓你找出其餘的。

+2

+1「剩下的留給學生做練習。」 – Marc 2010-05-05 12:22:49