concatenateOrderetSetMatrices

PURPOSE ^

obtain combinatorics for selecting up to k elements from n

SYNOPSIS ^

function orderedSetMatrix = concatenateOrderetSetMatrices(n, kMax, kMin)

DESCRIPTION ^

 obtain combinatorics for selecting up to k elements from n

 not-selected elements are indicated by 0

 THIS IS NO USER FUNCTION

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function orderedSetMatrix = concatenateOrderetSetMatrices(n, kMax, kMin)
0002 % obtain combinatorics for selecting up to k elements from n
0003 %
0004 % not-selected elements are indicated by 0
0005 %
0006 % THIS IS NO USER FUNCTION
0007 
0008 % The elk-library: convex geometry applied to crystallization modeling.
0009 %   Copyright (C) 2014 Alexander Reinhold
0010 %
0011 % This program is free software: you can redistribute it and/or modify it
0012 %   under the terms of the GNU General Public License as published by the
0013 %   Free Software Foundation, either version 3 of the License, or (at your
0014 %   option) any later version.
0015 %
0016 % This program is distributed in the hope that it will be useful, but
0017 %   WITHOUT ANY WARRANTY; without even the implied warranty of
0018 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0019 %   General Public License for more details.
0020 %
0021 % You should have received a copy of the GNU General Public License along
0022 %   with this program.  If not, see <http://www.gnu.org/licenses/>.
0023 
0024 %% input handling
0025 if ~exist('kMin', 'var') || isempty(kMin)
0026     kMin = 0;
0027 end
0028 
0029 %% determine output size
0030 amountVector = nan(1, (n+1) - kMin - (n-kMax));
0031 for iAmount = kMin:kMax
0032     amountVector(iAmount - kMin + 1) = nchoosek(n, iAmount);
0033 end
0034 startIndexVector = [0 cumsum(amountVector)];
0035 orderedSetMatrix = zeros(startIndexVector(end), kMax);
0036 
0037 
0038 %% fill matrix
0039 
0040 % cycle through the total number of elements to be selected
0041 for iAmount = kMin:kMax
0042     if iAmount == 0
0043         thisOrderedSetMatrix = [];
0044     else
0045         thisOrderedSetMatrix = obtainOrderedSetMatrix(n, iAmount);
0046     end
0047     orderedSetMatrix(...
0048         (startIndexVector(iAmount - kMin + 1)+1): ...
0049          startIndexVector(iAmount - kMin + 2), 1:iAmount) = ... 
0050           thisOrderedSetMatrix(end:-1:1, :);
0051 end

Generated on Sat 18-Jul-2015 16:45:31 by m2html © 2005