-
Notifications
You must be signed in to change notification settings - Fork 2
/
Cell.m
92 lines (75 loc) · 2.36 KB
/
Cell.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
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
% Cell is a reimplementation of matlabs cell array with the benefit that it is subclassable
% It might be used for giving a typename to a cellarray to increase readability of the code.
classdef Cell
properties
data
end
methods
function obj = Cell(data)
default_arg('data', {});
if ~iscell(data)
error('Input argument to Cell must be a cell array');
end
obj.data = data;
end
function str = toString(obj)
str = sprintf('%s%s', class(obj), toString(obj.data));
end
function s = size(A)
s = size(A.data);
end
function b = isempty(A)
b = prod(size(A)) == 0;
end
function l = length(A)
l = length(A.data);
end
function ind = end(A,k,n)
ind = builtin('end',A.data, k, n);
end
function B = transpose(A)
b = A.data.';
B = callConstructor(A, b);
end
function B = ctranspose(A)
b = A.data';
B = callConstructor(A, b);
end
function A = subsasgn(A, S, B)
a = subsasgn(A.data, S, B);
A = callConstructor(A, a);
end
function B = subsref(A, S)
switch S(1).type
case '()'
b = subsref(A.data, S(1));
B = callConstructor(A, b);
if length(S) > 1
B = subsref(B,S(2:end));
end
case '{}'
B = subsref(A.data, S);
case '.'
B = builtin('subsref',A, S);
otherwise
error('unreachable');
end
end
function C = horzcat(varargin)
dataArray = cell(1, length(varargin));
for i = 1:length(varargin)
dataArray{i} = varargin{i}.data;
end
c = horzcat(dataArray{:});
C = callConstructor(varargin{1}, c);
end
function C = vertcat(varargin)
dataArray = cell(1, length(varargin));
for i = 1:length(varargin)
dataArray{i} = varargin{i}.data;
end
c = vertcat(dataArray{:});
C = callConstructor(varargin{1}, c);
end
end
end