1function x = subsref(self,idx) 2 3assert(length(idx) == 1) 4 5if strcmp(idx.type,'()') 6 % load data 7 8 if strcmp(idx.type,'()') && length(idx.subs) == 1 ... 9 && length(idx.subs) < self.nd 10 % reference like A([2 3 1 5]) 11 12 if self.tooBigToLoad 13 % number of elements in x 14 ind = idx.subs{1}; 15 16 % transform index to subscript 17 subs = cell(1,self.nd); 18 [subs{:}] = ind2sub(size(self),ind); 19 20 % make a nice array length(ind) by self.nd 21 subs = cell2mat(subs); 22 23 % output array 24 x = zeros(size(ind)); 25 x(:) = NaN; 26 27 28 % get every element 29 % can be quite slow 30 idxe.type = '()'; 31 idxe.subs = cell(1,self.nd); 32 33 for i=1:length(ind) 34 idxe.subs = mat2cell(subs(i,:),1,ones(1,self.nd)); 35 x(i) = subsref(self,idxe); 36 end 37 else 38 % load full array 39 tmp = full(self); 40 x = subsref(tmp,idx); 41 end 42 else 43 [start, count, stride] = ncsub(self,idx); 44 45 if any(count == 0) 46 x = zeros(count); 47 else 48 x = ncread(cached_decompress(self.filename),self.varname,... 49 start,count,stride); 50 end 51 end 52elseif strcmp(idx.type,'.') 53 % load attribute 54 name = idx.subs; 55 % strmatch is obsolete 56 % index = strmatch(name,{self.vinfo.Attributes(:).Name}); 57 index = find(strcmp(name,{self.vinfo.Attributes(:).Name})); 58 59 60 if isempty(index) 61 error('variable %s has no attribute called %s',self.varname,name); 62 else 63 x = self.vinfo.Attributes(index).Value; 64 end 65else 66 error('not supported'); 67 68end 69 70 71% Copyright (C) 2012 Alexander Barth <barth.alexander@gmail.com> 72% 73% This program is free software; you can redistribute it and/or modify 74% it under the terms of the GNU General Public License as published by 75% the Free Software Foundation; either version 2 of the License, or 76% (at your option) any later version. 77% 78% This program is distributed in the hope that it will be useful, 79% but WITHOUT ANY WARRANTY; without even the implied warranty of 80% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 81% GNU General Public License for more details. 82% 83% You should have received a copy of the GNU General Public License 84% along with this program; If not, see <http://www.gnu.org/licenses/>. 85 86