Info

# How to call a function - with explanations

1 view (last 30 days)
Jay on 17 Sep 2018
Closed: MATLAB Answer Bot on 20 Aug 2021
I have viewed the MATLAB documentation and I am still confused.
I am attempting to use the
convdegminssecs.m
The code (to save time and since it is short):
% CONVDEGMINSSECS: converts degrees, mins, secs to decimal degrees and
% INPUTS: deg,mins,secs
%
% EXAMPLE of USAGE:
% convdegminssecs(45,54,55)
%
% ans = 45.9153
%
deg = deg + mins/60 + secs/3600;
end
If I have D.MS value of 38.4810 and want it converted to Degrees Decimals, when specifying the function in the main script, how and where do I stipulate the following:
1. - The value to be used / converted in the function being invoked (DMS value)
2. - The functions name
3. - The variable for the output (DD value)
Please state what each component of the command does what for ease of comprehension so I know how to call functions in the future.

Walter Roberson on 17 Sep 2018
Interpreting 38.4810 as meaning 38 degrees, 48 minutes, 10 seconds, then:
D_MS = 38.4810; %original in hybrid notation
D = fix(D_MS); %degrees
MS = round((abs(D_MS) - abs(D)) * 10000); %temporary variable to hold minutes and seconds in hybrid notation
M = floor(MS/100); %minutes
S = mod(MS, 100); %seconds
DD = convdegminssecs(D, M, S); %DD is output
This code does not assume that D_MS is a positive value: if that could be assumed then the code would be a little shorter.
##### 2 CommentsShowHide 1 older comment
Walter Roberson on 17 Sep 2018
The line