Borrar filtros
Borrar filtros

add uniform random number to matrix

3 visualizaciones (últimos 30 días)
NA
NA el 23 de Jul. de 2019
Respondida: Star Strider el 23 de Jul. de 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

Respuesta aceptada

Star Strider
Star Strider el 23 de Jul. de 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

Más respuestas (0)

Categorías

Más información sobre Random Number Generation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by