add uniform random number to matrix

3 次查看(过去 30 天)
I want to add uniform number which change for each element of matrix.
But if I use this code, same number add to element of A
A=[1,2;2,4];
index=1;
uniform_test=unifrnd(1,3);
A(index,:)=uniform_test+A(index, :);
example of result
A=[2.5*1,1.2*2;2,4];
change uniform number of each element of A

采纳的回答

Star Strider
Star Strider 2019-7-23
I am not certain what you are asking.
If you want to add different uniform random numbers with a minimum value of 1 and a maximum value of 3 to every element in ‘A’, you have to tell the unifrnd function to create a matrix the size of ‘A’.
Try this:
A=[1,2;2,4];
[r,c] = size(A);
uniform_test=unifrnd(1,3,r,c); % Random Matrix (Size Of ‘A’)
Anew = A + uniform_test

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Random Number Generation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by