comparison Cell.m @ 524:6aad1c4c8e01 feature/grids

Merge default
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 02 Aug 2017 15:46:10 +0200
parents 025f084187d1
children 2ce903f28193
comparison
equal deleted inserted replaced
523:3c062cc72986 524:6aad1c4c8e01
1 % Cell is a reimplementation of matlabs cell array with the benefit that it is subclassable
2 % It might be used for giving a typename to a cellarray to increase readability of the code.
3 classdef Cell
4 properties
5 data
6 end
7
8 methods
9 function obj = Cell(data)
10 default_arg('data', {});
11 if ~iscell(data)
12 error('Input argument to Cell must be a cell array');
13 end
14
15 obj.data = data;
16 end
17
18 function str = toString(obj)
19 str = sprintf('%s%s', class(obj), toString(obj.data));
20 end
21
22 function s = size(A)
23 s = size(A.data);
24 end
25
26 function l = length(A)
27 l = length(A.data);
28 end
29
30 function ind = end(A,k,n)
31 ind = builtin('end',A.data, k, n);
32 end
33
34 function B = transpose(A)
35 b = A.data.';
36 B = callConstructor(A, b);
37 end
38
39 function B = ctranspose(A)
40 b = A.data';
41 B = callConstructor(A, b);
42 end
43
44 function A = subsasgn(A, S, B)
45 a = subsasgn(A.data, S, B);
46 A = callConstructor(A, a);
47 end
48
49 function B = subsref(A, S)
50 switch S(1).type
51 case '()'
52 b = subsref(A.data, S(1));
53 B = callConstructor(A, b);
54 if length(S) > 1
55 B = subsref(B,S(2:end));
56 end
57 case '{}'
58 B = subsref(A.data, S);
59 case '.'
60 B = builtin('subsref',A, S);
61 otherwise
62 error('unreachable');
63 end
64 end
65
66 function C = horzcat(varargin)
67 dataArray = cell(1, length(varargin));
68
69 for i = 1:length(varargin)
70 dataArray{i} = varargin{i}.data;
71 end
72
73 c = horzcat(dataArray{:});
74 C = callConstructor(varargin{1}, c);
75 end
76
77 function C = vertcat(varargin)
78 dataArray = cell(1, length(varargin));
79
80 for i = 1:length(varargin)
81 dataArray{i} = varargin{i}.data;
82 end
83
84 c = vertcat(dataArray{:});
85 C = callConstructor(varargin{1}, c);
86 end
87 end
88 end