How do I generate a uniform random number from a 2d matrix to form a 3d matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
James Tursa
el 7 de Dic. de 2017
Editada: James Tursa
el 7 de Dic. de 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));
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!