how can I fill a matrix with randomly -0.01 and 0.01
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Simon Blum
el 23 de Mzo. de 2017
Comentada: Simon Blum
el 23 de Mzo. de 2017
I want to fill a matrix with only two diffrent numbers e.g. 0.01 and -0.01.
0 comentarios
Respuesta aceptada
Stephen23
el 23 de Mzo. de 2017
Editada: Stephen23
el 23 de Mzo. de 2017
>> V = [0.01,-0.01];
>> V(randi(numel(V),5,5))
ans =
-0.010000 0.010000 -0.010000 0.010000 0.010000
-0.010000 0.010000 0.010000 0.010000 -0.010000
-0.010000 -0.010000 0.010000 0.010000 -0.010000
0.010000 -0.010000 -0.010000 -0.010000 -0.010000
-0.010000 0.010000 -0.010000 0.010000 -0.010000
Although you could calculate the values from randi, this method using indexing has the advantage that the values are not calculated but are exactly those values that you define in V.
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices 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!