forked from episodes-platform/shared-snippets
Add code snippets
This commit is contained in:
25
matlab/unitutils/deg2km.m
Normal file
25
matlab/unitutils/deg2km.m
Normal file
@@ -0,0 +1,25 @@
|
||||
function km = deg2km(deg)
|
||||
%DEG2KM Convert distance from degrees to kilometers
|
||||
%
|
||||
% KM = DEG2KM(DEG) converts distances from degrees to kilometers as
|
||||
% measured along a great circle on a sphere with a radius of 6371 km, the
|
||||
% mean radius of the Earth.
|
||||
%
|
||||
% KM = DEG2KM(DEG,RADIUS) converts distances from degrees to kilometers
|
||||
% as measured along a great circle on a sphere having the specified
|
||||
% radius. RADIUS must be in units of kilometers.
|
||||
%
|
||||
% KM = DEG2KM(DEG,SPHERE) converts distances from degrees to kilometers,
|
||||
% as measured along a great circle on a sphere approximating an object in
|
||||
% the Solar System. SPHERE may be one of the following strings: 'sun',
|
||||
% 'moon', 'mercury', 'venus', 'earth', 'mars', 'jupiter', 'saturn',
|
||||
% 'uranus', 'neptune', or 'pluto', and is case-insensitive.
|
||||
%
|
||||
% See also DEG2NM, DEGTORAD, DEG2SM, KM2DEG.
|
||||
|
||||
% Copyright 1996-2009 The MathWorks, Inc.
|
||||
% $Revision: 1.10.4.4 $ $Date: 2009/03/30 23:38:09 $
|
||||
|
||||
rad = deg2rad(deg);
|
||||
|
||||
km = rad*6371;
|
12
matlab/unitutils/deg2rad.m
Normal file
12
matlab/unitutils/deg2rad.m
Normal file
@@ -0,0 +1,12 @@
|
||||
function angleInRadians = deg2rad(angleInDegrees)
|
||||
% DEG2RAD Convert angles from degrees to radians
|
||||
%
|
||||
% DEG2RAD has been replaced by DEGTORAD.
|
||||
%
|
||||
% angleInRadians = DEG2RAD(angleInDegrees) converts angle units from
|
||||
% degrees to radians.
|
||||
|
||||
% Copyright 2007-2009 The MathWorks, Inc.
|
||||
% $Revision: 1.9.4.5 $ $Date: 2009/04/15 23:16:12 $
|
||||
|
||||
angleInRadians = (pi/180) * angleInDegrees;
|
25
matlab/unitutils/km2deg.m
Normal file
25
matlab/unitutils/km2deg.m
Normal file
@@ -0,0 +1,25 @@
|
||||
function deg = km2deg(km)
|
||||
%KM2DEG Convert distance from kilometers to degrees
|
||||
%
|
||||
% DEG = KM2DEG(KM) converts distances from kilometers to degrees as
|
||||
% measured along a great circle on a sphere with a radius of 6371 km, the
|
||||
% mean radius of the Earth.
|
||||
%
|
||||
% DEG = KM2DEG(KM,RADIUS) converts distances from kilometers to degrees
|
||||
% as measured along a great circle on a sphere having the specified
|
||||
% radius. RADIUS must be in units of kilometers.
|
||||
%
|
||||
% DEG = KM2DEG(KM,SPHERE) converts distances from kilometers to degrees,
|
||||
% as measured along a great circle on a sphere approximating an object in
|
||||
% the Solar System. SPHERE may be one of the following strings: 'sun',
|
||||
% 'moon', 'mercury', 'venus', 'earth', 'mars', 'jupiter', 'saturn',
|
||||
% 'uranus', 'neptune', or 'pluto', and is case-insensitive.
|
||||
%
|
||||
% See also DEG2KM, KM2RAD, KM2NM, KM2SM.
|
||||
|
||||
% Copyright 1996-2009 The MathWorks, Inc.
|
||||
% $Revision: 1.10.4.4 $ $Date: 2009/03/30 23:38:30 $
|
||||
|
||||
rad = km/6371;
|
||||
|
||||
deg = rad2deg(rad);
|
12
matlab/unitutils/rad2deg.m
Normal file
12
matlab/unitutils/rad2deg.m
Normal file
@@ -0,0 +1,12 @@
|
||||
function angleInDegrees = rad2deg(angleInRadians)
|
||||
% RAD2DEG Convert angles from radians to degrees
|
||||
%
|
||||
% RAD2DEG has been replaced by RADTODEG.
|
||||
%
|
||||
% angleInDegrees = RAD2DEG(angleInRadians) converts angle units from
|
||||
% radians to degrees.
|
||||
|
||||
% Copyright 2007-2008 The MathWorks, Inc.
|
||||
% $Revision: 1.9.4.5 $ $Date: 2009/04/15 23:16:46 $
|
||||
|
||||
angleInDegrees = (180/pi) * angleInRadians;
|
65
matlab/unitutils/second.m
Normal file
65
matlab/unitutils/second.m
Normal file
@@ -0,0 +1,65 @@
|
||||
function s = second(d,f)
|
||||
%SECOND Seconds of date or time.
|
||||
% S = SECOND(D) returns the seconds given a serial date number or a
|
||||
% date string, D.
|
||||
%
|
||||
% S = SECOND(S,F) returns the second of one or more date strings S using
|
||||
% format string F. S can be a character array where each
|
||||
% row corresponds to one date string, or one dimensional cell array of
|
||||
% strings.
|
||||
%
|
||||
% All of the date strings in S must have the same format F, which must be
|
||||
% composed of date format symbols according to Table 2 in DATESTR help.
|
||||
% Formats with 'Q' are not accepted.
|
||||
%
|
||||
% For example, s = second(728647.558427893) or
|
||||
% s = second('19-Dec-1994, 13:24:08.17') returns s = 8.17.
|
||||
%
|
||||
% See also DATEVEC, MINUTE, HOUR.
|
||||
|
||||
% Copyright 1995-2008 The MathWorks, Inc.
|
||||
% $Revision: 1.6.2.6 $ $Date: 2008/12/21 01:51:09 $
|
||||
|
||||
if nargin < 1
|
||||
error('finance:second:missingInputs', 'Please enter D.')
|
||||
end
|
||||
if nargin < 2
|
||||
f = '';
|
||||
end
|
||||
|
||||
if ischar(d)
|
||||
d = datenum(d,f);
|
||||
sizeD = size(d);
|
||||
|
||||
elseif iscell(d)
|
||||
sizeD = size(d);
|
||||
d = datenum(d(:),f);
|
||||
|
||||
elseif isnumeric(d)
|
||||
sizeD = size(d);
|
||||
|
||||
else
|
||||
error('finance:second:invalidInputClass', ...
|
||||
'Invalid date/time class.')
|
||||
end
|
||||
|
||||
% Generate date vectors from dates.
|
||||
c = datevec(d(:));
|
||||
|
||||
% Extract seconds. Multiply by 1000 then round the result to make sure we avoid
|
||||
% roundoff errors for milliseconds.
|
||||
%extract seconds from hours
|
||||
sh = c(:,4)*3600;
|
||||
% extract second from minutes
|
||||
sm = c(:,5)*60;
|
||||
% extract seconds
|
||||
ss = c(:, 6);
|
||||
% round
|
||||
ss = sh + sm + ss;
|
||||
s = round(1000.*ss)./1000;
|
||||
|
||||
% Reshape into the correct dims
|
||||
s = reshape(s, sizeD);
|
||||
|
||||
|
||||
% [EOF]
|
7
matlab/unitutils/wavecut.m
Normal file
7
matlab/unitutils/wavecut.m
Normal file
@@ -0,0 +1,7 @@
|
||||
function [wc]=wavecut(wf,startp,endp)
|
||||
|
||||
wc=wf(round(startp):round(endp));
|
||||
|
||||
|
||||
|
||||
end
|
Reference in New Issue
Block a user