How do I generate a uniform random number from a 2d matrix to form a 3d matrix
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a vector A, such that A is 48X1, I need to create another matrix B from A, such that B is 48X1X5000 (i.e. a 3D matrix). Now I want all element in the first row of matrix B to be a random number that is within 0.8 times and 1.2 times the element in the first row of matrix A. All element in the second row of matrix B to be a random number that is within 0.8 times and 1.2 times the element in the 2nd row of matrix A. All element in the third row of matrix B to be a random number that is within 0.8 times and 1.2 times the element in the third row of matrix A, and so on till the 48th row. Remember B is a 3D matrix of 48 by 1 by 5000. Thank you. Looking forward to your support.
0 commentaires
Réponses (1)
James Tursa
le 7 Déc 2017
Modifié(e) : James Tursa
le 7 Déc 2017
E.g., later versions of MATLAB:
A = whatever;
f1 = 0.8;
f2 = 1.2;
n = 5000;
B = A .* (f1 + rand([size(A) n])*(f2-f1)));
Or earlier versions of MATLAB:
B = bsxfun(@times,A,f1 + rand([size(A) n])*(f2-f1));
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!