How to find the most common statistical value in an array?
10 views (last 30 days)
Show older comments
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" ?
0 Comments
Accepted Answer
Star Strider
on 27 Jun 2012
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.
4 Comments
Star Strider
on 28 Jun 2012
I'm glad it worked! It might be worthwhile for you to create a second data file, linearly resampling your original data uniformly to 10 Hz and using that dataset for convenience.
The histogram will create peaks corresponding to data frequencies. There are routines for finding and characterising chromatography peaks that would likely work on histogram peaks if you need to do this often.
Thank you for accepting my answer.
More Answers (2)
grapevine
on 27 Jun 2012
Take a look at this function:
mode - Most frequent values in array
5 Comments
Walter Roberson
on 27 Jun 2012
What would be permissible to access in that situation? The data used to create that graph? That graph appears to just be sort() of the original data, and when one is doing statistical work, the order of the data is not relevant (unless it is a time-dependent process), so having access to the sorted data would be equivalent to having access to the original data.
Image Analyst
on 28 Jun 2012
If your data are not integers, but are instead floating point numbers ( single or double), then depending on how they were generated, you may find that none of them are equal, even though you think they should be. See the FAQ on this topic: http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F In that case you should use hist() or histc() which will group values that are close to each other into bins.
0 Comments
See Also
Categories
Find more on Data Preprocessing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!