How can I extract random data from a matrix?
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi everyone.
I have a M rows by N columns matrix and I need to extract X random samples of it of the same size. I suposse is a simple task but I'm new at Matlab.
Thanks a lot.
댓글 수: 0
채택된 답변
Azzi Abdelmalek
2012년 9월 14일
편집: Azzi Abdelmalek
2012년 9월 14일
A=rand(10,5) %your matrix aray
B=A(:)
X=20; %number of random sample
[v,idx]=sort(rand(1,numel(A)));
Samples=B(idx(1:X))
댓글 수: 2
Azzi Abdelmalek
2012년 9월 16일
using Sean Wolski suggestion (randperm)
A=rand(10,5) %your matrix aray
Samples=A(randperm(numel(A),20))
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 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!