nextnchoosek.m

来自「Speaker Verification Toolbox」· M 代码 · 共 44 行

M
44
字号
function I = nextnchoosek(I,N)

% I = nextnchoosek(I,N) - Next nchoosek variable combination
%
% nextnchoosek -function returns the "next" nchoosek combination of integers
% between 1 and N. The "next" integer combination is taken in lexicographical
% order. Note that this functions does not check that whether or not the
% input variable combination I is proper/valid.
%
% Input variables:
% I     - Previous integer combination.
% N     - The largest integer that can appear in I.
%
% Output variables:
% I     - The next variable combination or empty matrix if
%         I = [N-lenght(I)+1,...,N-2,N-1,N] is in the input.
%
% Functions used:

% 09.04.2002 by Harri L鋒desm鋕i
% Modified:

% Upper bounds for each element in I.
N = [N-length(I)+1:N];

% Start to check I from right to left that whether or not its elements can be
% increase by one.
for j=length(I):-1:1
    % Take action if j:th element can be increased by one.
    if I(j)<N(j)
        I(j) = I(j) + 1;
        p = I(j) + 1;
        % Change the elements that are right from the j:th position and quit.
        for k=(j+1):length(I)
            I(k) = p;
            p = p + 1;
        end
        return;
    end % if I(j)<N(j)
end % for j=length(I):-1:1

% Set the output to empty matrix if the input arguments were not proper.
I = [];

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?