How can I sample n elements from each column of a matrix?
4 views (last 30 days)
Show older comments
I have this matrix:
A =
1 5 9 13 17
2 6 10 14 18
3 7 11 15 19
4 8 12 16 20
I want to sample n elments with replacement from each column. For instance, if n=2, I would like to get something like:
B =
2 8 10 14 20
4 8 9 15 17
I tried datasample, but it samples entire rows. Is there an efficient way to do this without using a for loop?
1 Comment
Accepted Answer
See Also
Categories
Find more on Multidimensional Arrays 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!