How to generate random matrix of 0 and 1 of distinct rows?

1 vue (au cours des 30 derniers jours)
Cantor Set le 21 Fév 2020
There is a function already in MATLAB GAtoolbox: crtbp.m that generates a random matrix of zeros and ones but when I performed the following loop I found that some instances there will be identical rows in the random matrix:
for i=1:200
Ro=crtbp(5,5);
u=unique(Ro, 'rows');
uu=size(u,1); rr=size(Ro,1);
if uu~=rr
x=1
break;
end
end
>> uniquetest
x =
1
______________________________________________________________________
I need the rows to be distincit, is there a function in matlab to do so ?
0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

Réponse acceptée

Spencer Chen le 21 Fév 2020
I don't know if there are any.
But it's easy to write one for your specific case where you only have 5 columns. That is quite mangeable, because you only will have 2^5 = 32 patterns to select from. Something like using randperm() then to pick 5 patterns from 32 would work for you.
Blessings,
Spencer
0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

Catégories

En savoir plus sur Genetic Algorithm dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by