How to select random number in a matrix?

1 visualizzazione (ultimi 30 giorni)
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.

Risposta accettata

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

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by