How to randomly extract 10 elements from that matrix
显示 更早的评论
i generate 1000*1 matrix through 'A=rand(100,1)'. And now i want to randomly extract 10 elements from that matrix.
How can i get that?!
回答(1 个)
A = rand(1000,1);
%10 random indices less than or equal to the number of elements in A
idx = randperm(numel(A),10)
out = A(idx)
2 个评论
Yoon Ju
2023-5-13
Dyuman Joshi
2023-5-14
"out" is just the variable to which I have assigned the output. You can change the name of the output as per what you want.
类别
在 帮助中心 和 File Exchange 中查找有关 Random Number Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!