Effacer les filtres
Effacer les filtres

how to put only one element randomly in row of matrix

3 vues (au cours des 30 derniers jours)
Meriem Ben Kalia
Meriem Ben Kalia le 11 Août 2020
Commenté : Meriem Ben Kalia le 11 Août 2020
Hello,
Can anyone help me please, I didn't a solution
I'd like to put only one element of row to 1 'randomly' and the other putted in 0
Exemple I have A= zeros (4,3) I like to get A= [0 1 0; 1 0 0; 0 0 1; 1 0 0]

Réponse acceptée

KSSV
KSSV le 11 Août 2020
Modifié(e) : KSSV le 11 Août 2020
A = zeros(4,3) ;
[m,n] = size(A) ;
for i = 1:m
idx = randperm(n,1) ;
A(i,idx) = 1 ;
end
  1 commentaire
Meriem Ben Kalia
Meriem Ben Kalia le 11 Août 2020
Thank you very much for the help you have given

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics 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