Can anyone please help in writing the code to generate a matrix of which each row should contain a new arrangement (permutation without repetition)?
I have tried the following:
%Generate an array of 8 elements randomly
array=floor(randi([0,100],1,K));
%Generate all permutations of 'array'. Each row signifies a new arrangement
%all_matrix=perms(array);
%// Create all possible permutations (with repetition) of letters stored in x
C = cell(K, 1); %// Preallocate a cell array
[C{:}] = ndgrid(array); %// Create K grids of values
y = cellfun(@(array){array(:)}, C); %// Convert grids to column vectors
all_matrix_repetition = [y{:}];
all_matrix=zeros(factorial(K),K);
for i=1:size(all_matrix_repetition,1)
if length(all_matrix_repetition(i,:))==length(unique(all_matrix_repetition(i,:)))
all_matrix(count,:)=all_matrix_repetition(i,:);
count=count+1;
end
end
But getting the memory error. I am using Matlab 2011a. Please help me.