random selection
显示 更早的评论
I have a matrix size of 96x249.How can i select 48 rows randomly and store it into a new matrix of 48x249.I have values in matrix as decimal numbers.
采纳的回答
更多回答(2 个)
Peter Perkins
2011-11-1
1 个投票
There are a number of ways to do this, including Walter's suggestion. But in addition, if you have access to MATLAB R2011b, there is the slightly simpler
NewMatrix = OldMatrix(randperm(96,48),:);
and if you have access to the Statistics Toolbox in R2011b, there is also
NewMatrix = datasample(OldMatrix,48);
The latter option also allows you to sample with weights, and with replacement. Of course, neither allows you to get the rest of the matrix.
类别
在 帮助中心 和 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!