-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharg.m
More file actions
35 lines (31 loc) · 755 Bytes
/
arg.m
File metadata and controls
35 lines (31 loc) · 755 Bytes
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
% value = arg(pos, type, default);
function value = arg(pos, type, default)
persistent index;
narginchk(2,3);
if isnumeric(pos)
args = evalin('caller', 'varargin');
if pos == 1
index = 1;
end
if length(args) >= index
value = args{index};
typeOk = isa(value, type);
else
typeOk = false;
end
elseif ischar(pos)
try
value = evalin('caller', pos);
typeOk = isa(value, type);
catch
typeOk = false;
end
end
if typeOk
index = index + 1;
elseif nargin == 3
value = default;
else
error(['Missing Arguent of Type ' type]);
end
end