1function B = subsref(self,idx)
2
3% handle case with a single subscript
4% for example CA(234)
5if strcmp(idx.type,'()') && length(idx.subs) == 1
6    % indices of elements in B
7    ind = idx.subs{1};
8
9    if strcmp(ind,':')
10        ind = [1:numel(self)]';
11    end
12
13    % output array
14    B = zeros(size(ind));
15    B(:) = NaN;
16
17    if self.overlap
18        % transform linear index ind to subscript subs
19        subs = cell(1,self.nd);
20        [subs{:}] = ind2sub(size(self),ind);
21
22        % make a nice array length(ind) by self.nd
23        subs = cell2mat(subs);
24
25
26        % get every element
27        idxe.type = '()';
28        idxe.subs = cell(1,self.nd);
29
30        for i=1:length(ind)
31            idxe.subs = mat2cell(subs(i,:),1,ones(1,self.nd));
32            B(i) = subsref_canonical(self,idxe);
33        end
34    else
35        % assume all arrays does not overlap
36
37        for j=1:self.na
38            sel = self.bounds(j) < ind & ind <= self.bounds(j+1);
39            B(sel) = self.arrays{j}(ind(sel) - self.bounds(j));
40        end
41
42    end
43elseif strcmp(idx.type,'.')
44  % load attributes from first array
45    B = subsref(self.arrays{1},idx);
46else
47    B = subsref_canonical(self,idx);
48end
49
50end
51
52% for this function we assume that idx.subs has the same dimension than
53% the array
54
55function B = subsref_canonical(self,idx)
56[idx_global,idx_local,sz] = idx_global_local_(self,idx);
57
58B = zeros(sz);
59B(:) = NaN;
60
61for j=1:self.na
62    % get subset from j-th array
63    subset = subsref(self.arrays{j},idx_local{j});
64
65    % set subset in global array B
66    % this is slow, why?
67    %B = subsasgn(B,idx_global{j},subset);
68
69    % however this quite fast
70    idxa = idx_global{j}.subs;
71    B(idxa{:}) = subset;
72end
73
74end
75
76
77% Copyright (C) 2012 Alexander Barth <barth.alexander@gmail.com>
78%
79% This program is free software; you can redistribute it and/or modify
80% it under the terms of the GNU General Public License as published by
81% the Free Software Foundation; either version 2 of the License, or
82% (at your option) any later version.
83%
84% This program is distributed in the hope that it will be useful,
85% but WITHOUT ANY WARRANTY; without even the implied warranty of
86% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
87% GNU General Public License for more details.
88%
89% You should have received a copy of the GNU General Public License
90% along with this program; If not, see <http://www.gnu.org/licenses/>.
91
92