Mercurial > repos > public > sbplib
comparison Cell.m @ 592:4422c4476650 feature/utux2D
Merge with feature/grids
author | Martin Almquist <martin.almquist@it.uu.se> |
---|---|
date | Mon, 11 Sep 2017 14:17:15 +0200 |
parents | 2ce903f28193 |
children |
comparison
equal
deleted
inserted
replaced
591:39554f2de783 | 592:4422c4476650 |
---|---|
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 b = isempty(A) | |
27 b = prod(size(A)) == 0; | |
28 end | |
29 | |
30 function l = length(A) | |
31 l = length(A.data); | |
32 end | |
33 | |
34 function ind = end(A,k,n) | |
35 ind = builtin('end',A.data, k, n); | |
36 end | |
37 | |
38 function B = transpose(A) | |
39 b = A.data.'; | |
40 B = callConstructor(A, b); | |
41 end | |
42 | |
43 function B = ctranspose(A) | |
44 b = A.data'; | |
45 B = callConstructor(A, b); | |
46 end | |
47 | |
48 function A = subsasgn(A, S, B) | |
49 a = subsasgn(A.data, S, B); | |
50 A = callConstructor(A, a); | |
51 end | |
52 | |
53 function B = subsref(A, S) | |
54 switch S(1).type | |
55 case '()' | |
56 b = subsref(A.data, S(1)); | |
57 B = callConstructor(A, b); | |
58 if length(S) > 1 | |
59 B = subsref(B,S(2:end)); | |
60 end | |
61 case '{}' | |
62 B = subsref(A.data, S); | |
63 case '.' | |
64 B = builtin('subsref',A, S); | |
65 otherwise | |
66 error('unreachable'); | |
67 end | |
68 end | |
69 | |
70 function C = horzcat(varargin) | |
71 dataArray = cell(1, length(varargin)); | |
72 | |
73 for i = 1:length(varargin) | |
74 dataArray{i} = varargin{i}.data; | |
75 end | |
76 | |
77 c = horzcat(dataArray{:}); | |
78 C = callConstructor(varargin{1}, c); | |
79 end | |
80 | |
81 function C = vertcat(varargin) | |
82 dataArray = cell(1, length(varargin)); | |
83 | |
84 for i = 1:length(varargin) | |
85 dataArray{i} = varargin{i}.data; | |
86 end | |
87 | |
88 c = vertcat(dataArray{:}); | |
89 C = callConstructor(varargin{1}, c); | |
90 end | |
91 end | |
92 end |