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!