KerMor  0.9
Model order reduction for nonlinear dynamical systems and nonlinear approximation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RangeSplitter.m
Go to the documentation of this file.
1 
2 
3 /* (Autoinserted by mtoc++)
4  * This source code has been filtered by the mtoc++ executable,
5  * which generates code that can be processed by the doxygen documentation tool.
6  *
7  * On the other hand, it can neither be interpreted by MATLAB, nor can it be compiled with a C++ compiler.
8  * Except for the comments, the function bodies of your M-file functions are untouched.
9  * Consequently, the FILTER_SOURCE_FILES doxygen switch (default in our Doxyfile.template) will produce
10  * attached source files that are highly readable by humans.
11  *
12  * Additionally, links in the doxygen generated documentation to the source code of functions and class members refer to
13  * the correct locations in the source code browser.
14  * However, the line numbers most likely do not correspond to the line numbers in the original MATLAB source files.
15  */
16 
18  :public handle {
37  public:
38 
40 
41 
42  private:
43 
44  np;
51  partpos = "[]";
60  public:
61 
63  if isempty(total)
64  error(" Total range value must be specified. ");
65  end
66  this.Total= total;
67 
68  ip.addParamValue('Max',[]);
69  ip.addParamValue('Num',[]);
70  ip.parse(varargin[:]);
71  res = ip.Results;
72  if ~isempty(res.Max)
73  pos = 0:res.Max:total;
74  if (pos(end) < total)
75  pos = [pos total];
76  end
77  this.np= length(pos)-1;
78  this.partpos= pos;
79  elseif ~isempty(res.Num)
80  if res.Num > total
81  error(" Cannot have more parts than total elements ");
82  end
83  this.np= res.Num;
84  sizes = ones(1,this.np)*floor(total/res.Num);
85  rest = mod(total,res.Num);
86  if rest > 0
87  sizes(1:rest) = sizes(1:rest)+1;
88  end
89  this.partpos= [0 cumsum(sizes)];
90  else
91  error(" You must specify either a maximum part size or the number of parts. ");
92  end
93 
94  }
95 
96 
97  function np = getNumParts() {
98  np = this.np;
99  }
100 
101 
102  function pt = getPart(nr) {
103  if nr > this.np
104  error(" Only %d parts present. ",this.np);
105  end
106  pt = this.partpos(nr)+1:this.partpos(nr+1);
107  }
108 
109 
110  public: /* ( Static ) */
111 
112  static function res = test_RangeSplitter() {
113  res = true;
114  rs = RangeSplitter(1000," Num ",1);
115  res = res && rs.getNumParts == 1;
116  res = res && isequal(1:1000,rs.getPart(1));
117 
118  rs = RangeSplitter(1000," Num ",4);
119  res = res && rs.getNumParts == 4;
120  res = res && isequal(1:250,rs.getPart(1));
121  res = res && isequal(751:1000,rs.getPart(4));
122 
123  rs = RangeSplitter(1001," Max ",250);
124  res = res && rs.getNumParts == 5;
125  res = res && isequal(1:250,rs.getPart(1));
126  res = res && isequal(751:1000,rs.getPart(4));
127  res = res && isequal(1001:1001,rs.getPart(5));
128 
129  rs = RangeSplitter(100," Max ",19);
130  res = res && rs.getNumParts == 6;
131 
132  rs = RangeSplitter(100," Max ",20);
133  res = res && rs.getNumParts == 5;
134 
135  rs = RangeSplitter(100," Max ",21);
136  res = res && rs.getNumParts == 5;
137  res = res && isequal(1:21,rs.getPart(1));
138  res = res && isequal(22:42,rs.getPart(2));
139  res = res && isequal(43:63,rs.getPart(3));
140  res = res && isequal(64:84,rs.getPart(4));
141  res = res && isequal(85:100,rs.getPart(5));
142 
143  rs = RangeSplitter(6," Num ",4);
144  res = res && isequal(1:2,rs.getPart(1));
145  res = res && isequal(3:4,rs.getPart(2));
146  res = res && isequal(5,rs.getPart(3));
147  res = res && isequal(6,rs.getPart(4));
148 
149  rs = RangeSplitter(9," Num ",4);
150  res = res && isequal(1:3,rs.getPart(1));
151  res = res && isequal(4:5,rs.getPart(2));
152  res = res && isequal(6:7,rs.getPart(3));
153  res = res && isequal(8:9,rs.getPart(4));
154 
155  try
156  rs = RangeSplitter(10);/* #ok */
157 
158  res = false;
159  catch ME/* #ok */
160 
161  res = res && true;
162  end
163 
164  try
165  rs = RangeSplitter(10," Num ",14);/* #ok */
166 
167  res = false;
168  catch ME/* #ok */
169 
170  res = res && true;
171  end
172  }
173 
174 
175 
176 };
177 
Matlab's base handle class (documentation generation substitute)
A variable number of input arguments.
function pt = getPart(nr)
RangeSplitter(total, varargin)
Definition: RangeSplitter.m:62
function np = getNumParts()
Definition: RangeSplitter.m:97
RangeSplitter:
Definition: RangeSplitter.m:17
static function res = test_RangeSplitter()