How to select random number in a matrix?

1 回表示 (過去 30 日間)
Moe
Moe 2014 年 11 月 21 日
回答済み: Image Analyst 2014 年 11 月 21 日
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.

採用された回答

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by