find mode of an array but if there is no mode then return a random number
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Johanna Popp
am 3 Mär. 2022
Kommentiert: Johanna Popp
am 3 Mär. 2022
Hi all,
I am trying to find the mode of the columns in a matrix A. My problem is, if there is no similar value in the column, the mode function always returns the lowest possible number. Instead of the lowest possible numer I would like to have a random number from the collumn with no mode.
Any help would be appreciated!!
Thanks,
Johanna
0 Kommentare
Akzeptierte Antwort
Steven Lord
am 3 Mär. 2022
Use the third output from a call to mode. If that third output is not a cell containing a scalar the mode is not unique and therefore I think you want to choose one of those elements as 'the' mode.
There's an example on its documentation page, 'Mode of Matrix Rows with Frequency and Multiplicity Information', that you may be able to adapt.
Weitere Antworten (1)
Image Analyst
am 3 Mär. 2022
There are many ways to do this. For example you can use mode(), find(), unique(), histcounts(), and of course you'll need randi() or randperm(). Is this homework? If so what have you tried?
0 Kommentare
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping 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!