How can I extract random data from a matrix?

2 views (last 30 days)
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.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 14 Sep 2012
Edited: Azzi Abdelmalek on 14 Sep 2012
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 Comments
Gerardo
Gerardo on 16 Sep 2012
Thanks for your help Azzi, it works great.
Azzi Abdelmalek
Azzi Abdelmalek on 16 Sep 2012
using Sean Wolski suggestion (randperm)
A=rand(10,5) %your matrix aray
Samples=A(randperm(numel(A),20))

Sign in to comment.

More Answers (1)

Sean de Wolski
Sean de Wolski on 14 Sep 2012
doc randperm

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!