Mercurial > repos > public > sbplib
annotate Cell.m @ 468:13362cf4dd89 feature/sublassable_cellarray
Make the overloaded methods call the subclass constructor
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 01 Aug 2017 12:41:42 +0200 |
parents | 8d3c3da3a589 |
children | 365fcdbb8736 |
rev | line source |
---|---|
467 | 1 classdef Cell |
2 properties | |
3 data | |
4 end | |
5 methods | |
6 function obj = Cell(data) | |
7 if ~iscell(data) | |
8 class(data) | |
9 error('Input argument to Cell must be a cell array') | |
10 end | |
11 | |
12 obj.data = data; | |
13 end | |
14 | |
15 % function display(A) | |
16 % n = size(A.data); | |
17 | |
18 % sizeStr = join(cellfun(@num2str, num2cell(n), 'UniformOutput',false),'x'); | |
19 % header = [sizeStr, 'Cell'] | |
20 | |
21 % disp() | |
22 % disp(A.data) | |
23 % % display(A.data) | |
24 % end | |
25 | |
26 function disp(A) | |
27 disp(A.data) | |
28 end | |
29 | |
30 function A = subsasgn(A, S, B) | |
31 disp(S); | |
32 a = subsasgn(A.data, S, B); | |
468
13362cf4dd89
Make the overloaded methods call the subclass constructor
Jonatan Werpers <jonatan@werpers.com>
parents:
467
diff
changeset
|
33 A = callConstructor(A, a); |
467 | 34 end |
35 | |
36 function B = subsref(A, S) | |
37 disp(S); | |
38 B = subsref(A.data, S); | |
39 % Wrong if type is '()', '.' | |
40 end | |
41 | |
42 function C = horzcat(varargin) | |
43 dataArray = cell(1, length(varargin)); | |
44 | |
45 for i = 1:length(varargin) | |
46 dataArray{i} = varargin{i}.data; | |
47 end | |
48 | |
49 c = horzcat(dataArray{:}); | |
468
13362cf4dd89
Make the overloaded methods call the subclass constructor
Jonatan Werpers <jonatan@werpers.com>
parents:
467
diff
changeset
|
50 C = callConstructor(varargin{1}, c); |
467 | 51 end |
52 | |
53 function vertcat(varargin) | |
54 dataArray = cell(1, length(varargin)); | |
55 | |
56 for i = 1:length(varargin) | |
57 dataArray{i} = varargin{i}.data; | |
58 end | |
59 | |
60 c = vertcat(dataArray{:}); | |
468
13362cf4dd89
Make the overloaded methods call the subclass constructor
Jonatan Werpers <jonatan@werpers.com>
parents:
467
diff
changeset
|
61 C = callConstructor(varargin{1}, c); |
467 | 62 end |
63 end | |
468
13362cf4dd89
Make the overloaded methods call the subclass constructor
Jonatan Werpers <jonatan@werpers.com>
parents:
467
diff
changeset
|
64 end |