-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctionTemplateMN.m
More file actions
93 lines (74 loc) · 2.27 KB
/
Copy pathfunctionTemplateMN.m
File metadata and controls
93 lines (74 loc) · 2.27 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
%% filename.m
% (c) Michael Nickerson YYYY-MM-DD
% Brief description of function
%
% Requirements:
% - List of required files
% - And required state of equipment
%
% Usage: [outputs, if, any] = functionName(required, inputs[, option, [value]])
% Returns:
% output: Description
%
% Parameters:
% required: Description of requirement
%
% Options:
% 'flagname'[, valueOrType]: Description of functionality (default value)
%
% TODO:
% - Any known TODOs
function [dataOut1, dataOut2] = functionTemplateMN(requiredIn, varargin)
%% Defaults and magic numbers
quiet = 0;
myParam = [];
%% Argument parsing
% Check required inputs
if isempty(requiredIn) || ~isa(requiredIn, 'double')
error('Required input "requiredIn" is not a double!');
end
% Accept a struct.option = value structure
if numel(varargin) > 0 && isstruct(varargin{1})
paramStruct = varargin{1}; varargin(1) = [];
varargin = [reshape([fieldnames(paramStruct) struct2cell(paramStruct)]', 1, []), varargin];
end
% Parameter parsing
while ~isempty(varargin)
arg = lower(varargin{1}); varargin(1) = [];
if isempty(arg); continue; end
% Look for valid arguments
switch arg
case {"singleopt", "alias"}
myParam = double(nextarg("my required parameter"));
case "quiet"
quiet = 1;
otherwise
if ~isempty(arg)
warning("Unexpected option '%s', ignoring", num2str(arg));
end
end
end
%% Dependent variable processing, if any
%% Helper functions, if any
% Overwrite previous output if passed; quiet if quiet set
function out = utilDisp(out, varargin)
if ~quiet
if numel(varargin) > 0; lastout = varargin{1}; else; lastout = ''; end;
fprintf(repmat('\b', 1, strlength(lastout)));
fprintf(out);
end
end
% Get the next argument or error
function arg = nextarg(strExpected)
if isempty(strExpected); strExpected = ''; end
if ~isempty(varargin)
arg = varargin{1}; varargin(1) = [];
else
error('Expected next argument "%s", but no more arguments present!', strExpected);
end
end
%% Process stuff
dataOut1 = mean(requiredIn);
%% Analyze stuff
dataOut2 = 1./dataOut1;
end