⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 combinations.m

📁 机器学习所有源码
💻 M
字号:
function indices = combinations (in_from, N)

% Find all N combinations of input indices 
%
% Inputs:
%   in_from - The input indices
%   N       - How many indices are requiered
%
% Outputs:
%   indices - The indice combinations

Nf = length(in_from);

comb_mat  = zeros(2^Nf, Nf);
basic_mat = [0, 1];

for i = 1:Nf,
    rep_mat     = ones(2^(i-1), 1) * basic_mat;
    pattern     = rep_mat(:);
    rep_pattern = pattern * ones(1, 2^(Nf-i));
    column      = rep_pattern(:);
    comb_mat(:,Nf - i + 1) = column;
end

%Find the number of the right rows
in = find(sum(comb_mat') == N);

indices = zeros(length(in), N);
for i = 1:length(in),
    cur_in = find(comb_mat(in(i), :));
    indices(i, :) = in_from(cur_in);
end

⌨️ 快捷键说明

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