How can I generate ALL possible values for an N*M matrix, knowing that elements of this matrix can only be either be 0 or 1?
For example if I want a 2*2 matrix, we g
Another possibility (although Divakar's answer is simpler and probably faster):
c = cell(1,N*M);
[c{end:-1:1}] = ndgrid([0 1 2 3 ]); %// or change set of values: [0 1 2 3] etc
combs = cell2mat(cellfun(@(x) x(:), c, 'uni', 0)); %// results as row vectors
combs = reshape(combs.',N,M,[]); %// NxM matrices: combs(:,:,1), combs(:,:,2),...