trix subscripts to be included in the loop's current
    %      cell element.
    %   TREF is a copy of REF, but replaces the 0's with []'s so that the
    %      indexing makes apprpriate empty cells instead of trying to index
    %      with 0, which would cause an error.
    %   REFSTATIC keeps track of which TREF's are [] as the dimension
    %      counter, DIMCOUNTS, increments through each of the cells. This
    %      is required since adding 0 when incrementing the references
    %      returns a value that REF needs to know, but the index should be
    %      [].
    refstart = cell(size(cellsize));
    for n=1:length(refstart)
        refstart{n} = 1:varargin{n}(1);
        if isempty(refstart{n})
            refstart{n} = 0;
        end
    end
    ref = refstart;
    ref{1} = 0;
    tref = ref;
    refstatic = zeros(1,length(cellsize));

    % Construct cell elements by looping through absolute indices and extracting
    %   the appropriate matrix subscripts
    for cind = 1:numel(c)
        % Find the next cell dimension that needs to be incremented
        inc = find(dimcounts<cellsize, 1, 'first');
        % Update the dimension counter using the incremental cell dimension
        dimcounts(1:inc) = [ones(1,inc-1) dimcounts(inc)+1];
 
        % Update the set of matrix subscripts, REF, by indexing into the input 
        %   arguments

        % If not incrementing the first cell dimension, then update REF with the
        %   appropriate earlier cell dimensions as well
        if inc~=1
            [ref{1:inc-1}] = deal(refstart{1:inc-1});
            refstatic(1:inc-1) = 0;
        end
        
        % If we are adding an empty matrix when updating this increment's
        %   reference, then add 0 instead, but index with [], and set the
        %   REFSTATIC tracker.
        if ~varargin{inc}(dimcounts(inc))
            ref{inc} = ref{inc}(end);
            refstatic(inc) = 1;
        else
            % When updating an increment's reference without adding 0,
            %   reset the REFSTATIC tracker
            ref{inc} = ref{inc}(end)+(1:varargin{inc}(dimcounts(inc)));
            refstatic(inc) = 0;
        end
                                
        % If any references are 0, change them to empty so that we are
        % indexing correctly, else let TREF{n} take on REF{n}
        for n = 1:length(refstatic)
            if ~any(ref{n}) || refstatic(n)
                tref{n} = [];
            else
                tref{n} = ref{n};
            end
        end
        
        % Finally construct the cell element by indexing into the matrix
        c{cind} = x(tref{:});

    end
end
