MATLAB: How to extract random data from a matrix

random sample

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.

Best Answer

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))