How do i select random indicies from an array?
显示 更早的评论
I have an array of 10 by 6. is there a way I can randomly select rows from this particular array and everything within it.
采纳的回答
更多回答(1 个)
Joseph Cheng
2015-3-5
编辑:Joseph Cheng
2015-3-5
yes, you can perform something like this. Lets say your 10 by 6 array is called A;
then to get the random row(s) you can do
A(randi(10,N,1),:)
where 10 is the number or rows in A (or you can do size(A,1) if you do not want to hard code 10), N is the number of random rows you want to select and the : selects all columns.
2 个评论
Image Analyst
2015-3-5
Just a watchout: With randi(), it's really random meaning that there is a possibility that the same row might be "chosen" twice or more. If you don't want that (you want, say, 5 rows and all rows to be unique), then use randperm() instead.
ME
2015-3-5
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!