generating random values from another matrix with a random value in rows only
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
HASAN AL-KAF
le 12 Sep 2017
Modifié(e) : James Tursa
le 12 Sep 2017
Hi I have this code
X = rand(113,401); % sample matrix
% generate random indices and use them to pull values from A
B = X(round(rand(11300,401)*(numel(X)-1))+1);
but i want only exchange randomly in the row so value in row 1 in X can go randomly in any rows in B matrix only not in any column of B matrix
0 commentaires
Réponse acceptée
James Tursa
le 12 Sep 2017
Modifié(e) : James Tursa
le 12 Sep 2017
Is something like this what you want? Randomly distributed values from X but staying in same column?
X = whatever
rows = desired number of rows of the result B
[M,N] = size(X);
B = X(bsxfun(@plus,randi(M,rows,N),M*(0:N-1)));
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices 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!