How to select random numbers from array for creating new matrix?

5 vues (au cours des 30 derniers jours)
Azad Asadov
Azad Asadov le 11 Déc 2018
Commenté : Azad Asadov le 11 Déc 2018
I have b1 array. b1=[-3,-1,1,3,5];
I want to create 3x4 matrix by using random elements of b1 array.
So, one of expected outputs:
ans= -1 5 -3 1
1 -3 5 -3
3 5 1 3
Anyone can help?

Réponse acceptée

Stephan
Stephan le 11 Déc 2018
Modifié(e) : Stephan le 11 Déc 2018
Hi,
try:
b1=[-3,-1,1,3,5];
A = b1(randi(numel(b1),3,4))
possible result:
A =
1 -1 -3 3
-3 5 -3 3
-1 -3 3 1
Best regards
Stephan

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by