How do I generate a uniform random number from a 2d matrix to form a 3d matrix
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
James Tursa
am 7 Dez. 2017
Bearbeitet: James Tursa
am 7 Dez. 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));
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!