function [Result] = makeTuples(varargin)

nInputArgs = length(varargin);
b = cell(1, nInputArgs);
a = flip(varargin);

[b{:}] = ndgrid(a{:});
bb = flip(b);
nOutputs = length(bb);
N = numel(bb{1});

Result = zeros(N, nInputArgs);
arr = zeros(1,nInputArgs);
for j = 1:N
    for k = 1:nOutputs
        arr(k) = bb{k}(j);
    end
    Result(j,:) = arr;
    arr = zeros(1,nInputArgs);
end
end