MATLAB: How to find the most common statistical value in an array

common statistical valuecommon unknown valuecommon valueunknown array

Assume that the array consists of real time recordings and appears to have five common values with unknown std (e.g. 5.1356 +/- 1.265, 13.2136 +- 1.564 and so on….). How could you find the most common values in that array with its limits included? One way to do that would be to use the mode function with predefined edges for your common values. But how could you do that without "cheating" ?

Best Answer

I've had to deal with these sorts of problems, so after looking at the plot of your data (that do not appear to be too noisy at least w.r.t. the transition step magnitudes), as an initial approach I suggest:
datadif = diff([0; data]); % (for a column vector) note that starting with '0' results in 'datadif' being the same length as 'data' with essentially the same relative indices
then graph it (perhaps on the same axes as 'data') and see if the +ve spikes in 'datadif' will help you define where your data subset limits are. If it looks good, then use 'find' (with a threshold) or something similar to identify the x-axis indices for the transitions. After that. a 'for' loop might be the best way to calculate your summary statistics on each subset, especially if you only need them (since you data look flat between the transitions) and you apparently only need to deal with your data once.
I'm not sure this is the answer you're looking for, but it will help you define your data subsets if that is part of the solution to your problem.