T = tril(X) The point was to create an index of the initially empty and initially filled cells. It may not be the most elegant solution, but a few for loops did work.
initiallyFilled = [];
i = 0;
for collumns = 1:X
for lines = 1:X
i = i+1 % this gives the index of the cell being evaluated
if lines > collumns
initiallyFilled = [initiallyFilled i]; % Agregates a filled cell index.
end
end
end
Then it's created a similar pattern for the initially empty cells. Difference being that lines < collumns on the final "if" statement. initiallyEmpty = []; i = 0;
for collumns = 1:X
for lines = 1:Y
i = i+1 % this gives the index of the cell being evaluated
if lines < collumns
initiallyEmpty = [initiallyEmpty i]; % Agregates an empty cell index.
end
end
end
In the end, it's a matter of choosing how many permutations will happens. For instance, I was doing some percents of the total, so:
numberOfPermutations = sum(T);
After that, it's just about randomizing wich index are going to be carried from one side to the other and, then, deleting the used index from the list of possibilities.
for a = 1:numberOfPermutations
removedFilled = ceil(rand() * lenght(inittialyFilled));
filledEmpty = ceil(rand() * lenght(inittialyEmpty));
T(initiallyFilled(removedFilled)) = 0;
T(inittialyEmpty(filledEmpty)) = 1;
initiallyFilled(removedFilled) = [];
inittialyEmpty(filledEmpty) = [];
end