Thread Subject: local maxima of a histogram

Subject: local maxima of a histogram

From: James

Date: 7 Jan, 2008 17:58:01

Message: 1 of 7

   Is there a MATLAB function to calculate all the local
maxima of a histogram?

    Otherwise, I think I`ll have to calculate the mode,
remove (or zero) that value, then calculate it again, down
to some specified level.

   I have to find all the maxima, then test to see if any
of the maxima are within a given value of the others, then
do some more combining.

           Thanks, Alan



Subject: local maxima of a histogram

From: neuromath

Date: 7 Jan, 2008 18:13:49

Message: 2 of 7

James wrote:
> Is there a MATLAB function to calculate all the local
> maxima of a histogram?
>
> Otherwise, I think I`ll have to calculate the mode,
> remove (or zero) that value, then calculate it again, down
> to some specified level.
>
> I have to find all the maxima, then test to see if any
> of the maxima are within a given value of the others, then
> do some more combining.
>
> Thanks, Alan

Not sure I completely understand what you need, but assuming that you
are dealing with an m x n matrix of values that represent your
histogram data, you can use the 'max' command to tell MATLAB to find
the max along a particular dimension (see 'help max' for more). One of
many solutions would be to use 'repmat' and 'diff' to do the second
part of your analysis.

Subject: local maxima of a histogram

From: Rob S

Date: 7 Jan, 2008 18:25:03

Message: 3 of 7

James,

Try using histc, and then sorting the output.

Hope this helps,
Rob S.

"James " <jalanNOSPAMthomas@verizon.net> wrote in message
<fltp79$4l8$1@fred.mathworks.com>...
> Is there a MATLAB function to calculate all the local
> maxima of a histogram?
>
> Otherwise, I think I`ll have to calculate the mode,
> remove (or zero) that value, then calculate it again,
down
> to some specified level.
>
> I have to find all the maxima, then test to see if any
> of the maxima are within a given value of the others,
then
> do some more combining.
>
> Thanks, Alan
>
>
>

Subject: local maxima of a histogram

From: Rob S

Date: 7 Jan, 2008 18:55:04

Message: 4 of 7

More specifically...

numpoints = 1000;
data = floor(randn(numpoints,1)*100)+500;
counts = histc(data,1:numpoints);
[freq,value] = sort(counts,'descend');

So then the most frequent value will be value(1), which
occurs freq(1) times. The next most frequent value is value
(2) which occurs freq(2) times. Etc.

Cheers,
Rob S.

"Rob S" <rslazas.dontspamme@gmail.com> wrote in message
<fltqpv$h38$1@fred.mathworks.com>...
> James,
>
> Try using histc, and then sorting the output.
>
> Hope this helps,
> Rob S.
>
> "James " <jalanNOSPAMthomas@verizon.net> wrote in message
> <fltp79$4l8$1@fred.mathworks.com>...
> > Is there a MATLAB function to calculate all the
local
> > maxima of a histogram?
> >
> > Otherwise, I think I`ll have to calculate the mode,
> > remove (or zero) that value, then calculate it again,
> down
> > to some specified level.
> >
> > I have to find all the maxima, then test to see if
any
> > of the maxima are within a given value of the others,
> then
> > do some more combining.
> >
> > Thanks, Alan
> >
> >
> >
>

Subject: local maxima of a histogram

From: Miroslav Balda

Date: 7 Jan, 2008 20:20:20

Message: 5 of 7

"Rob S" <rslazas.dontspamme@gmail.com> wrote in message
<fltsi8$4g4$1@fred.mathworks.com>...
> More specifically...
>
> numpoints = 1000;
> data = floor(randn(numpoints,1)*100)+500;
> counts = histc(data,1:numpoints);
> [freq,value] = sort(counts,'descend');
>
> So then the most frequent value will be value(1), which
> occurs freq(1) times. The next most frequent value is value
> (2) which occurs freq(2) times. Etc.
>
> Cheers,
> Rob S.
>
> "Rob S" <rslazas.dontspamme@gmail.com> wrote in message
> <fltqpv$h38$1@fred.mathworks.com>...
> > James,
> >
> > Try using histc, and then sorting the output.
> >
> > Hope this helps,
> > Rob S.

SNIP

Hi
The above process does not give only extremes, but a
sequence of the largest class frequencies. The given problem
solves the function

function [Lx,Xh] = mnxtr(hist)
% Extremes of histogram
% hist (m,n) matrix class frequencies
% Lx logical matrix of peaks of hist
% Xh cell array of extremes in hist rows
[m,n] = size(hist);
Lx = false(m,n);
Xh = {};
for k = 1:m
    Lhl = extr(hist(k,:));
    Lx(k,:) = Lhl{1}';
    Xh = [Xh; {hist(Lx(k,:))}];
end

Try
m=10; n=15;
hst = round(rand(m,n)*100) % matrix of class frequencies
[Lx,Xh]=mnxtr(hist)
Xh{2} % extremes in the second row of hst

Hope it helps

Mira


Subject: local maxima of a histogram

From: Miroslav Balda

Date: 7 Jan, 2008 20:29:01

Message: 6 of 7

Function extr is from FEX, Id. 10272

Mira

Subject: local maxima of a histogram

From: Peter Perkins

Date: 8 Jan, 2008 16:44:30

Message: 7 of 7

James wrote:
> Is there a MATLAB function to calculate all the local
> maxima of a histogram?
>
> Otherwise, I think I`ll have to calculate the mode,
> remove (or zero) that value, then calculate it again, down
> to some specified level.
>
> I have to find all the maxima, then test to see if any
> of the maxima are within a given value of the others, then
> do some more combining.

It's worth noting that in many situations the local maxima in a
histogram will be very dependent on the bin that you use. So unless you
have some a priori reason for choosing a specific set of bins (e.g., you
have integer data), you might think about using something like KSDENSITY
from the Statistics Toolbox instead of a histogram. It does kernel
density estimation, which is, roughly, like a smoothed histogram, and
does not depend on choosing a particular set of bins.

Hope this helps.

- Peter Perkins
   The MathWorks, Inc.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
histogram peaks Miroslav Balda 7 Jan, 2008 15:24:59
histogram James 7 Jan, 2008 13:00:14
local maxima James 7 Jan, 2008 13:00:14
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com