MATLAB Answers

randomly select elements of an array

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


Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 12 Apr 2012
msize = numel(YourMatrix);
idx = randperm(msize);
If you have a fairly new version of MATLAB, you can instead use
msize = numel(YourMatrix);
YourMatrix(randperm(msize, x))


Show 6 older comments
Walter Roberson
Walter Roberson on 30 Nov 2020
YourMatrix(randi(size(YourMatrix,1)), ColumnNumber)
Jaime Gurrola
Jaime Gurrola on 7 Dec 2020
Hi walter, i want to select a random element from this array, help please

Sign in to comment.

More Answers (1)

Prasobhkumar P. P.
Prasobhkumar P. P. on 28 Jul 2020
histHandle= histfit(data,nBins,'normal');
[Val Ind] = max(histHandle(2).YData); %histHandle(2) corresponds to the curve fitted
M = histo18(2).XData(Ind);


Sign in to comment.


Community Treasure Hunt

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

Start Hunting!