function [d, m, s] = deg2dms(deg) % deg2dms -- Convert degrees to degrees-minutes-seconds. % [d, m, s] = deg2dms(deg) converts the angle deg (in degrees) % to degrees d, minutes m, and seconds s, all negative if % the original angle is negative. % str = deg2dms(deg) returns the result as a string, suitable % for labeling a graph. % Copyright (C) 2001 Dr. Charles R. Denham, ZYDECO. % All Rights Reserved. % Disclosure without explicit written consent from the % copyright owner does not constitute publication. % Version of 25-Sep-2001 16:29:26. % Updated 25-Sep-2001 16:29:26. if ischar(deg), deg = eval(deg); end x = abs(deg); d = floor(x); x = (x - d) * 60; m = floor(x); x = (x - m) * 60; s = x; if deg < 0 d = -d; m = -m; s = -s; end if nargout < 2 d = int2str(d); m = int2str(abs(m)); s = num2str(abs(s)); if length(m) < 2, m = ['0' m]; end f = find(s == '.'); if isempty(f) if length(s) < 2, s = ['0' s]; end elseif f(1) == 2 s = ['0' s]; end d = [d char(161) m char(39) s char(34)]; end