How to separate a matrix randomly
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
zaki
le 30 Nov 2014
Réponse apportée : Andrei Bobrov
le 1 Déc 2014
Hello everyone, I want to ask how to separate a matrix randomly. For example, I have a matrix
A = [...
0 0 0 0
0 0 0 0
1 1 1 1
1 1 1 1]
and I need a C1 and C2 matrix:
C1 =
0 0 0 0
0 0 0 0
1 0 0 1
0 1 1 0
C2 =
0 0 0 0
0 0 0 0
0 1 1 0
1 0 0 1
Is it possible we can generate them by separating the 1 digit randomly?
Thanks before :)
0 commentaires
Réponse acceptée
Stephen23
le 1 Déc 2014
Randomly allocate all values from one matrix to two other matrices:
>> A = [0,0,0,0;0,0,0,0;1,1,1,1;1,1,1,1];
>> B = 0.5<rand(size(A));
>> C1 = zeros(size(A)); C2 = zeros(size(A));
>> C1(B) = A(B);
>> C2(~B) = A(~B);
If you only require the last two rows of values, then you can "&" the index with another logical matrix giving the restrictions that you require.
0 commentaires
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Image Processing Toolbox 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!