-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
foo.m
33 lines (26 loc) · 735 Bytes
/
foo.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
function varargout = foo(varargin)
[varargout{1:nargout}] = dispatch(varargin,...
{@foo1,["any"]; % dispatch based on number of inputs
@foo2, ["logical","logical"]; % dispatch based on type
@foo3, ["numeric", "logical"];
@foo3, ["logical", "numeric"]; % repeated method for different type
@foo4, ["Person"]; % dispatch on class
@foo5, ["any", "logical"]});
end
function out = foo1(a)
out = a;
end
function out = foo2(a, b)
out = logical(a && b);
end
function out = foo3(a, b)
out = a * b;
end
function [out1, out2] = foo4(p)
out1 = p.name;
out2 = p.age;
end
function [out1, out2] = foo5(a,b)
out1 = b;
out2 = a;
end