-
Notifications
You must be signed in to change notification settings - Fork 0
/
degminsec2decdeg.m
48 lines (46 loc) · 1.42 KB
/
degminsec2decdeg.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function [decdeg] = degminsec2decdeg(degminsec)
%DEGMINSEC2DECDEG Convert degree minutes seconds to decimal degrees
%
% Syntax:
% decdeg = DEGMINSEC2DECDEG(degminsec)
%
% Description:
% Utility to convert latitude and longitude coordinates from degrees
% minutes seconds to decimal degrees
%
% Inputs:
% degminsec N-by-3 matrix of coordinates in degrees minutes seconds
% with degrees in the first column and minutes in the
% second column, and seconds in the third column
%
% Outputs:
% decdeg N-by-1 vector of coordinates in decimal degrees
%
% Examples:
% degminsec = [30 29 12; -118 58 59];
% decdeg = degminsec2decdeg(degminsec)
% decdeg =
% 30.4867
% -118.9831
%
% See also DECDEG2DEGMINSEC, DECDEG2DEGMIN, DEGMIN2DECDEG
%
% Authors:
% S. Fregosi <[email protected]> <https://github.com/sfregosi>
%
% FirstVersion: 10 September 2021
% Updated: 12 May 2023
%
% Created with MATLAB ver.: 9.9.0.1524771 (R2020b) Update 2
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
decdeg = zeros(length(degminsec(:,1)), 1);
for f = 1:length(degminsec(:,1))
secDec = degminsec(f,3)/60;
minDec = (degminsec(f,2) + secDec)/60;
deg = degminsec(f,1);
if deg > 0
decdeg(f,1) = deg + minDec;
else
decdeg(f,1) = deg - minDec;
end
end