How to change a range of numbers in a matrix to a random number of a matrix?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Voss
il 23 Feb 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]))
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Random Number Generation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!