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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by