How to select random number in a matrix?

1 visualización (últimos 30 días)
Moe
Moe el 21 de Nov. de 2014
Respondida: Image Analyst el 21 de Nov. de 2014
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.

Respuesta aceptada

Image Analyst
Image Analyst el 21 de Nov. de 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);

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by