Skip to content

Instantly share code, notes, and snippets.

@tesch1
Created June 27, 2018 11:37
Show Gist options
  • Save tesch1/2ea5964e4be469d71cf1398e26bbe399 to your computer and use it in GitHub Desktop.
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
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, tesch1@gmail.com
% 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