MATLAB Answers

add uniform random number to matrix

10 views (last 30 days)
NA on 23 Jul 2019
Answered: Star Strider on 23 Jul 2019
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

0 Comments

Sign in to comment.

Accepted Answer

Star Strider on 23 Jul 2019
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 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!