-
Notifications
You must be signed in to change notification settings - Fork 5
/
machinery.m
42 lines (42 loc) · 1.02 KB
/
machinery.m
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
classdef machinery
methods(Static)
%% handy overloads
function out=isa(var,types)
if iscellstr(types)
out=any(cellfun(@(i) isa(var,i),types));
else
out=isa(var,types);
end
end
%% parser with some defaults and quicker declaration
function p=inputParser(varargin)
%init the object
p=inputParser;
%implement reasonable and safe input parser options
p.KeepUnmatched=true;
p.PartialMatching=false;
%implement requested options (may overwrite the defaults forced above)
for i=1:numel(varargin)/2
p.(varargin{2*i-1})=varargin{2*i};
end
end
%% flow control
function [out,success]=trycatch(success,errorID,func,args)
if ~success
try
out=func(args{:});
success=true;
catch ME
switch ME.identifier
case errorID
%do nothing
otherwise
rethrow(ME)
end
end
else
out=[];
end
end
end
end