How to change a range of numbers in a matrix to a random number of a matrix?
2 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Voss
on 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]))
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!