Filter löschen
Filter löschen

add uniform random number to matrix

3 Ansichten (letzte 30 Tage)
NA
NA am 23 Jul. 2019
Beantwortet: Star Strider am 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

Akzeptierte Antwort

Star Strider
Star Strider am 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

Weitere Antworten (0)

Kategorien

Mehr zu Random Number Generation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by