How to chose random row which contain non-zero element
Afficher commentaires plus anciens
For example ;
A=[ 0 0 0 0 ;
0 0 0 0;
0 0 0 0;
0 0 0 8;
0 0 0 0;
0 0 8 11;
0 0 0 0;
0 0 11 14;
11 0 0 14;
0 0 0 0;
0 8 9 14;
0 9 0 0;
0 9 0 14;
8 9 11 0;
0 0 0 0;]
If all row element zero for example row 15 I want to take another row random which contain non zero element
Réponse acceptée
Plus de réponses (1)
Andrei Bobrov
le 5 Avr 2017
another variant
inz = find(any(A ~= 0,2));
out = A(inz(randperm(numel(inz),1)),:);
Catégories
En savoir plus sur NaNs dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!