This question is closed. Reopen it to edit or answer.
How to call a function - with explanations
1 view (last 30 days)
I have viewed the MATLAB documentation and I am still confused.
I am attempting to use the
The code (to save time and since it is short):
function [deg,rad] = convdegminssecs(deg,mins,secs)
% CONVDEGMINSSECS: converts degrees, mins, secs to decimal degrees and
% output answer in decimal degrees and radians
% INPUTS: deg,mins,secs
% OUTPUTS: deg,rad
% EXAMPLE of USAGE:
% ans = 45.9153
deg = deg + mins/60 + secs/3600;
rad = deg * pi/180;
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:
- - The value to be used / converted in the function being invoked (DMS value)
- - The functions name
- - 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.
Thank you in advance.
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.