rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
ICompositeMatrix.m
1 classdef ICompositeMatrix < handle
2  %classdef ICompositeMatrix
3  % Handle class holding a cell array for a "composite-matrix".
4 
5 
6  %% properties
7  properties (Access = protected)
8  M; % cell array storing the matrices
9  end
10 
11 
12  %% methods
13  methods (Abstract)
14  % s = size(this, dim)
15  % returns a characteristic size
16  s = size(this, dim);
17 
18  % mat = getMatrix(this)
19  % returns one matrix
20  mat = getMatrix(this);
21 
22  % res = copy(this)
23  % creates deep copy
24  res = copy(this);
25  end
26 
27  methods (Sealed)
28 
29  function res = length(this)
30  % length of cell array
31  res = length(this.M);
32  end
33 
34  function this = set(this, mat, index)
35  % sets one cell
36  if index > length(this)
37  error('ICompositeMatrix:set', 'index too large');
38  end
39  this.M{index} = mat;
40  end
41 
42  function mat = get(this, index)
43  % returns one cell or sub-matrix
44  if max(index) > length(this)
45  error('ICompositeMatrix:get', 'index too large');
46  end
47  if length(index) == 1
48  mat = this.M{index};
49  else
50  mat = copy(this);
51  mat.M = mat.M(index);
52  end
53  end
54 
55  function obj1 = horzcat(obj1, obj2)
56  % horizontal concatenation
57  if isempty(obj1)
58  if isa(obj2, 'handle')
59  obj1 = copy(obj2);
60  else
61  obj1 = obj2;
62  end
63  else
64  for i = 1:obj2.length
65  obj1.M{i} = horzcat(obj1.M{i}, obj2.M{i});
66  end
67  end
68  end
69 
70  function mat = ctranspose(this)
71  % transposition, returns matrix
72  mat = ctranspose(this.getMatrix);
73  end
74 
75  function mat = plus(obj1, obj2)
76  % matrix addition
77  if isa(obj1, 'VecMat.ICompositeMatrix')
78  if isa(obj2, 'VecMat.ICompositeMatrix')
79  mat = getMatrix(obj1) + getMatrix(obj2);
80  else
81  mat = getMatrix(obj1) + obj2;
82  end
83  else
84  mat = obj1 + getMatrix(obj2);
85  end
86  end
87 
88  function mat = minus(obj1, obj2)
89  % matrix subtraction
90  if isa(obj1, 'VecMat.ICompositeMatrix')
91  if isa(obj2, 'VecMat.ICompositeMatrix')
92  mat = getMatrix(obj1) - getMatrix(obj2);
93  else
94  mat = getMatrix(obj1) - obj2;
95  end
96  else
97  mat = obj1 - getMatrix(obj2);
98  end
99  end
100 
101  function mat = mtimes(obj1, obj2)
102  % multiplication with array or composite-matrix
103  if isa(obj1, 'VecMat.ICompositeMatrix')
104  if isa(obj2, 'VecMat.ICompositeMatrix')
105  mat = getMatrix(obj1) * getMatrix(obj2);
106  else
107  mat = getMatrix(obj1) * obj2;
108  end
109  else
110  mat = obj1 * getMatrix(obj2);
111  end
112  end
113 
114  function mat = mldivide(obj1, mat)
115  % matrix division
116  mat = mldivide(getMatrix(obj1), mat);
117  end
118 
119  function varargout = subsref(this, S)
120  % subscript reference to matrix
121  if S.type(1) == '.'
122  [varargout{1:nargout}] = builtin('subsref', this, S);
123  else
124  [varargout{1:nargout}] = subsref(getMatrix(this), S);
125  end
126  end
127 
128  function M = subsasgn(this, S, B)
129  % return matrix
130  M = subsasgn(getMatrix(this), S, B);
131  end
132  end
133 
134 end
Handle class holding a cell array for a "composite-matrix".