How to select random number in a matrix?

The following command can find all max values in each iteration of matrix m and then chose first one:
[rowsOfMaxes colsOfMaxes] = find(m(:,:,j) == maxValue,1,'random');
I'm looking for a command that chose random one between all found max values.

 Accepted Answer

% Get a random index.
randomIndex = randi(numel(rowsOfMaxes), 1);
% Extract one row and one column from the lists.
randomRow = rowsOfMaxes(randomIndex);
randomCol = colsOfMaxes(randomIndex);

More Answers (0)

Categories

Asked:

Moe
on 21 Nov 2014

Answered:

on 21 Nov 2014

Community Treasure Hunt

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

Start Hunting!