How to select random number in a matrix?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Moe
am 21 Nov. 2014
Beantwortet: Image Analyst
am 21 Nov. 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.
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 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);
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!