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

3 ビュー (過去 30 日間)
Onovo
Onovo 2017 年 12 月 7 日
コメント済み: Onovo 2017 年 12 月 7 日
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 Center および File ExchangeRandom Number Generation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by