How to change a range of numbers in a matrix to a random number of a matrix?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Sumanth
el 23 de Feb. de 2023
Comentada: Voss
el 27 de Feb. de 2023
G = (1:125);
G = reshape(1:125,[25,5]);
x = setdiff(0:24, 2:25);
G is my matrix now i want to change element values ranging from 2 to 25 to random number from x
How can i do it??
0 comentarios
Respuesta aceptada
Voss
el 23 de Feb. de 2023
G = reshape(1:125,[25,5])
x = setdiff(0:24, 2:25)
idx = G >= 2 & G <= 25;
G(idx) = x(randi(numel(x),[nnz(idx),1]))
2 comentarios
Más respuestas (0)
Ver también
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!