How to extract random elements from an array?
6 views (last 30 days)
Show older comments
Twisha Bansal
on 23 Dec 2019
Edited: Badavath Swetha
on 28 Jun 2021
For eg., I have a 1d array, d=[1;3;4;6;8;7;8;9;6;7] and I need to extract the first, third and sixth variable. How do I do that?
1 Comment
Stephen23
on 23 Dec 2019
"I need to extract the first, third and sixth variable."
There is only one variable, the vector d.
The vector d has elements, and most likely you are trying to extract those elements.
Accepted Answer
Walter Roberson
on 23 Dec 2019
d([1 3 6])
If you want 3 at random then,
d( randperm(length(d),3) )
0 Comments
More Answers (1)
See Also
Categories
Find more on Elementary Math 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!