Created
June 27, 2018 11:37
-
-
Save tesch1/2ea5964e4be469d71cf1398e26bbe399 to your computer and use it in GitHub Desktop.
an implementation of combvec that anyone can use, ie for octave or missing nnet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function c = mtcombvec(varargin) | |
% my own implementation of combvec for use in octave or without matlab nnet library | |
% | |
% takes args of column-vectors, produces all combinations thereof | |
% | |
% copyright (c) 2018 Michael Tesch, [email protected] | |
% released under the Apache 2.0 Open Source license. | |
if length(varargin)==0 | |
c = []; | |
return | |
end | |
c = varargin{1}; | |
for i=2:length(varargin) | |
% make sure varargin{i} isn't more than 2d matrix | |
if length(size(varargin{i}))>2 | |
error(sprintf('parameters must be 2d matrices (check arg %d)', i)); | |
end | |
c = mtextend(c, varargin{i}); | |
end | |
function cc = mtextend(old, new) | |
mm = size(old,2); | |
nn = size(new,2); | |
cc = repmat(old, 1, nn); | |
cc = [cc ; repmat(new, 1, mm)]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment