Matlab code to find the most repeatedly occuring highest value in the array.

Hi everybody I have the following list of numbers and I want to find the most repeatedly occuring highest value. I tried using mode but it gives ne the most repeatedly occuring lowest value. How can I get the most repeated highest value?
Also if my number is the format 4.566754E-11 or 3.9972378E-10 is there anyway I can make matlab ignore the E-11 oe E-10 tempüorarily and just round the value to one numver after decimal point?
eg: 4.566754E-11 --> 4.6E-11
I have attached in an excel sheet some values which I have in my matlan array for your reference.
Looking forward to your help.

1 commentaire

If I understand correctly: You are looking for the most frequent value in an array, and if there are several values appearing with the same frequency the highest value is wanted. Correct?

Connectez-vous pour commenter.

Réponses (2)

You could try this:
a = [7 8 6 6 8 8 9 10 8 6 8 8 6 6 6]
[counts, edges] = histcounts(a)
modeIndexes = find(counts == max(counts))
greatestMode = ceil(edges(modeIndexes(end)))
Jan
Jan le 13 Mai 2015
Modifié(e) : Jan le 13 Mai 2015
You are looking for two different criteria: Most frequent and highest. This is simply impossible. You can find either the most frequent value, or the highest. Please give us a meaningful definition with a small example of what you want to achieve.
There are a lot of rounding function, simply search for "Matlab round significant digits". Should be digits be ignored for the calculations or for the display only?

4 commentaires

Snehalatha
Snehalatha le 14 Mai 2015
Modifié(e) : Snehalatha le 14 Mai 2015
Hi jan, I meant a matlab code to find the most frequently occuring highest number.
eg: 7 8 6 6 8 8 9 10 8 6 8 8 6 6 6
for the above 8 would be the answer as it the number which occurs repeatedly and also is higher than 6 though they appear with the same frequency. though 10 is the highest it will not be chosen because it occurs only once or twice.
But i was able to solve my problem by tweaking the mode() function a bit so I am good with the first part of my question.
The second part. I want the digits to be ignored for the calculations. I tried rounding but that just rounds my number to zero since the values I have are very small.
Thank you.
Please post how you tried to apply the rounding.
I didn't do any rounding as round() function rounded all my digits to zero. So I just used the following program without rounding
function[maxPDCharge,freqMaxPD]=getmaxcharge(chargeValues)
%to make the max value the minimum multiply by -1
chargeValues= (-1*chargeValues);
% use mode function to find the minimum value of array which is
% actually our maximum
[maxPDCharge,freqMaxPD]=mode(chargeValues);
%disp the actual PD value using absolute function
maxPDCharge = abs(maxPDCharge);
end
mode() selects the minimum value. so I multiplied my array with -1 and used mode thereby selecting the maximum value
[EDITED, Jan, Code formatted]
mode() replies the most frequent value, so the multiplication by -1 is not a reliable method to prefer the higher values.
You have written: "I tried rounding but that just rounds my number to zero since the values I have are very small." Please post how you tried to round. Then we can suggest an improvement.

Connectez-vous pour commenter.

Commenté :

Jan
le 17 Mai 2015

Community Treasure Hunt

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

Start Hunting!

Translated by