How do I generate a uniform random number from a 2d matrix to form a 3d matrix

1 次查看(过去 30 天)
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.

回答(1 个)

James Tursa
James Tursa 2017-12-7
编辑:James Tursa 2017-12-7
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));

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by