MatrixBerryCore
combvec.m
Go to the documentation of this file.
1 function indMat = combvec(varargin)
2 nInputs=nargin;
3 if nInputs==0
4  indMat = [];
5 else
6  indMat = varargin{1};
7  for iInp=2:nInputs
8  curVec = varargin{iInp};
9  indMat = [addBlockedInd(indMat,size(curVec,2));...
10  addInterleavedInd(curVec,size(indMat,2))];
11  end
12 end
13 %
14 function indResMat = addBlockedInd(indMat,nElems)
15 [nDims,nCombs] = size(indMat);
16 indResMat = zeros(nDims,nCombs*nElems);
17 indVec = 1:nCombs;
18 for iCombToAdd=(0:(nElems-1))*nCombs
19  indResMat(:,indVec+iCombToAdd) = indMat;
20 end
21 %
22 function indResMat = addInterleavedInd(indMat,nElems)
23 [nDims,nCombs] = size(indMat);
24 indResMat = zeros(nDims*nElems,nCombs);
25 ind = 1:nDims;
26 for iCombToAdd=(0:(nElems-1))*nDims
27  indResMat(ind+iCombToAdd,:) = indMat;
28 end
29 indResMat = reshape(indResMat,nDims,nElems*nCombs);
function addInterleavedInd(in indMat, in nElems)
function addBlockedInd(in indMat, in nElems)
function combvec(in varargin)
COMBVEC creates a matrix of combinations with elements from input vectors.