MATLAB: Is it possible to obtain a random sample of values from a matrix without the randsample tool

MATLABrandom sample

Is it possible to obtain a random sample of values from a matrix without the randsample tool?

Best Answer

A=magic(6);
out=A(randi(numel(A),1))
if you want 3 values for example
out=A(randi(numel(A),3,1))