How to find the most common statistical value in an array?

7 visualizzazioni (ultimi 30 giorni)
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" ?

Risposta accettata

Star Strider
Star Strider il 27 Giu 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 Commenti
ref
ref il 28 Giu 2012
Ok Strider, it seems that
datadif = diff([0; data]);
worked, but with a little data manipulation. My measurements had a frequency of 8-10 Hz, so diff function did not work in the first place. But after averaging with a factor equal to frequency it worked just fine. See pic plz. http://imageshack.us/photo/my-images/14/diffe.jpg/ I do not have time to check if the histogram works, but i will though.
Star Strider
Star Strider il 28 Giu 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.

Accedi per commentare.

Più risposte (2)

grapevine
grapevine il 27 Giu 2012
Take a look at this function:
mode - Most frequent values in array
  5 Commenti
Walter Roberson
Walter Roberson il 27 Giu 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.
ref
ref il 27 Giu 2012
Hi Walter. Yes obviously the data are permissible to access. I just plotted them that way to prove that sorted from smallest to largest value, the mean values are easier to be observed from anyone. The original data file is time depended, but again the problem is to find a mean value with its std.

Accedi per commentare.


Image Analyst
Image Analyst il 28 Giu 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.

Categorie

Scopri di più su Data Preprocessing in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by