Skip to content

Commit

Permalink
nDDict.m: Can now supply extra trailing [], :, or 1 to xp.subset. For…
Browse files Browse the repository at this point in the history
… example, xp(2,3,1,1,1,:,1,[]) should not return error even if ndims(xp)==2.
  • Loading branch information
davestanley committed Apr 3, 2017
1 parent 03ca99e commit 71cbb90
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion classes/@nDDict/nDDict.m
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,22 @@
clear selection2
end

% Trim back selection if too long. If size(obj.data_pr) is MxN,
% it is okay for selection to be {5,3,Y,Z} as long as Y and Z
% are either empty (:) or ones. If they are anything else,
% return error!
Ns = length(selection);
if Ns > Na
% Make sure extra selection entries are either "1" or []
selection_extra = selection(Na+1:end);
are_empties = cellfun(@isempty,selection_extra);
are_ones = cellfun(@(s) s == 1, selection_extra);
if any(~(are_empties | are_ones)) % If any of the extra selections are NOT either empty or one's...
error('Index exceeds dimensions of nDDict.data');
end
selection = selection(1:Na);
end

% Replace any ':' entries in selection with []. Empty
% entries code for taking all entries along a dimension; ':' is
% an alias for this.
Expand All @@ -121,7 +137,7 @@
% If Ns is still wrong dimensions, return error
Ns = length(selection);
if Ns ~= Na
error('Number of inputs must match dimensionality of nDDict.data_pr');
error('Number of inputs must match dimensionality of nDDict.data');
end

% Convert selection to index if using regular expressions
Expand Down

0 comments on commit 71cbb90

Please sign in to comment.