MATLAB: Randomly select elements of an array

matrix

Hi How i can select randomly elements from a matrix o array
I have the matrix and i want to select "x" numbers of elements
thanks

Best Answer

msize = numel(YourMatrix);
idx = randperm(msize);
YourMatrix(idx(1:x))
If you have a fairly new version of MATLAB, you can instead use
msize = numel(YourMatrix);
YourMatrix(randperm(msize, x))