MATLAB: How to eliminate equal matrices that are created randomly inside loop

eliminateequalityloopMATLABmatricesrandom

The code segment I'm working on is given below:
NphaseSteps = 6;
phases = exp( 2*pi*1i * (0:(NphaseSteps-1))/NphaseSteps );
i = 1;
while i <= 10 %number of iterations
ind = randi([1 NphaseSteps],10,10);
inField{i} = phases(ind);
save('inField.mat', 'inField')
i = i + 1;
end
Now, what I want is to keep track of these randomly created matrices "inField{i}" and eliminate the ones that are equal to each other. I know that I can use "if" condition but since I'm new to programming I don't know how to use it more efficiently so that it doesn't take too much time. So, I need your help for a fast working program that does the job. Thanks in advance.

Best Answer

A = phases;
n = 10; m = 10; %each output will be 10 x 10
rows_needed = 10; %you need 10 of them
cols_needed = n*m;
permidx = [];
more_needed = rows_needed;
while more_needed > 0
trial_idx = randi([1 NphaseSteps], more_needed, cols_needed);
permidx = unique([permidx; trial_idx], 'rows', 'stable');
more_needed = rows_needed - size(permidx,1);
end
randperms = A(permidx);
inField = cellfun(@(M) reshape(M, m, n), num2cell(randperms, 2), 'uniform', 0);
Related Question