How can I extract random data from a matrix?

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.

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2012년 9월 14일
편집: Azzi Abdelmalek 2012년 9월 14일

0 개 추천

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

Gerardo
Gerardo 2012년 9월 16일
Thanks for your help Azzi, it works great.
using Sean Wolski suggestion (randperm)
A=rand(10,5) %your matrix aray
Samples=A(randperm(numel(A),20))

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터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!

Translated by