Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Finding Maximum Points in an Array

Subject: Finding Maximum Points in an Array

From: Richard Wylde

Date: 26 Nov, 2010 18:41:04

Message: 1 of 13

Hi there,

I have the following problem: I have a large dataset (over 10,000 values), which I have plotted. Most of these values are zero (or very close to zero). However, there are around 9 'spikes' in the graph - it is the value of these that I am interested in. They are not, however, all the same value, and occur randomly in time.

How can I write a program that will find these values, and output both the value and the time that the value occurs at? I've tried various things, but nothing consistently picks out all points.


I appreciate the help.

Subject: Finding Maximum Points in an Array

From: Matt Fig

Date: 26 Nov, 2010 20:09:04

Message: 2 of 13

You could use the SORT function, with both outputs of course.

Subject: Finding Maximum Points in an Array

From: Miroslav Balda

Date: 26 Nov, 2010 20:10:05

Message: 3 of 13

"Richard Wylde" <rwylde@gmail.com> wrote in message <icouvv$hgp$1@fred.mathworks.com>...
> Hi there,
>
> I have the following problem: I have a large dataset (over 10,000 values), which I have plotted. Most of these values are zero (or very close to zero). However, there are around 9 'spikes' in the graph - it is the value of these that I am interested in. They are not, however, all the same value, and occur randomly in time.
>
> How can I write a program that will find these values, and output both the value and the time that the value occurs at? I've tried various things, but nothing consistently picks out all points.
>
> I appreciate the help.
>
Hi Richard,

If your data are in the vector "a", then the commands
     b = sort(a,'descend');
     x = b(1:9);
give 9 maximum values into x.

Mira

Subject: Finding Maximum Points in an Array

From: Richard Wylde

Date: 26 Nov, 2010 20:53:03

Message: 4 of 13

"Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <icp46t$hrd$1@fred.mathworks.com>...
> "Richard Wylde" <rwylde@gmail.com> wrote in message <icouvv$hgp$1@fred.mathworks.com>...
> > Hi there,
> >
> > I have the following problem: I have a large dataset (over 10,000 values), which I have plotted. Most of these values are zero (or very close to zero). However, there are around 9 'spikes' in the graph - it is the value of these that I am interested in. They are not, however, all the same value, and occur randomly in time.
> >
> > How can I write a program that will find these values, and output both the value and the time that the value occurs at? I've tried various things, but nothing consistently picks out all points.
> >
> > I appreciate the help.
> >
> Hi Richard,
>
> If your data are in the vector "a", then the commands
> b = sort(a,'descend');
> x = b(1:9);
> give 9 maximum values into x.
>
> Mira

Thank you. Will this also output the time (or at least number in the array) at which these values occur, or is there a way that I can do this? It's important that I know both the maximum values, and where they occur.

Thanks again,

Richard.

Subject: Finding Maximum Points in an Array

From: ImageAnalyst

Date: 26 Nov, 2010 21:11:07

Message: 5 of 13

Richard:
I suggest you look at Brett Shoelson's deleteoutliers() function in
the File Exchange:
http://www.mathworks.com/matlabcentral/fileexchange/3961

I'm sure you could adapt it to identify the outliers. For example, if
necessary, reshape your array into a 1D vector. Then look at his
example - the outliers are identified by NaN's. Then you could use
the isnan() function to "find" where those outliers live. Use
ind2sub() if you need to get back to 2D row,col coordinates because
your original array is a 2D array.
-ImageAnalyst

Subject: Finding Maximum Points in an Array

From: Walter Roberson

Date: 26 Nov, 2010 21:29:59

Message: 6 of 13

On 10-11-26 02:10 PM, Miroslav Balda wrote:
> "Richard Wylde" <rwylde@gmail.com> wrote in message
> <icouvv$hgp$1@fred.mathworks.com>...

>> I have the following problem: I have a large dataset (over 10,000
>> values), which I have plotted. Most of these values are zero (or very
>> close to zero). However, there are around 9 'spikes' in the graph - it
>> is the value of these that I am interested in. They are not, however,
>> all the same value, and occur randomly in time.

>> How can I write a program that will find these values, and output both
>> the value and the time that the value occurs at? I've tried various
>> things, but nothing consistently picks out all points.

> Hi Richard,

> If your data are in the vector "a", then the commands
> b = sort(a,'descend');
> x = b(1:9);
> give 9 maximum values into x.

I cannot tell from the original posting whether the 'spikes' are single points
each and the 9 largest are to be returned, or if the 'spikes' each consist of
a rise and a drop over several points and it is the location of the highest
point of 9 of these rise/drop areas that are to be found ? To use other
wording, are the 'spikes' single points, or are they "peaks"?

If the 'spikes' are peaks, then the method Miroslav shows is not certain to
work, as it is possible (and likely) that a point that is on the rise or fall
of a peak but not at the top of the peak, will happen to be greater than the
highest point of a different peak.


Another point I have to ask is whether the 'spikes' are certain to be
positive? If not, then instead of sorting on value, one would have to sort on
absolute value.

Subject: Finding Maximum Points in an Array

From: Miroslav Balda

Date: 26 Nov, 2010 22:15:04

Message: 7 of 13

Walter Roberson <roberson@hushmail.com> wrote in message <icp8sv$4ns$1@canopus.cc.umanitoba.ca>...
> On 10-11-26 02:10 PM, Miroslav Balda wrote:
> > "Richard Wylde" <rwylde@gmail.com> wrote in message
> > <icouvv$hgp$1@fred.mathworks.com>...
>
> >> I have the following problem: I have a large dataset (over 10,000
> >> values), which I have plotted. Most of these values are zero (or very
> >> close to zero). However, there are around 9 'spikes' in the graph - it
> >> is the value of these that I am interested in. They are not, however,
> >> all the same value, and occur randomly in time.
> > Hi Richard,
>
> > If your data are in the vector "a", then the commands
> > b = sort(a,'descend');
> > x = b(1:9);
> > give 9 maximum values into x.
>
> I cannot tell from the original posting whether the 'spikes' are single points
> each and the 9 largest are to be returned, or if the 'spikes' each consist of
> a rise and a drop over several points and it is the location of the highest
> point of 9 of these rise/drop areas that are to be found ? To use other
> wording, are the 'spikes' single points, or are they "peaks"?
>
> If the 'spikes' are peaks, then the method Miroslav shows is not certain to
> work, as it is possible (and likely) that a point that is on the rise or fall
> of a peak but not at the top of the peak, will happen to be greater than the
> highest point of a different peak.
>
>
> Another point I have to ask is whether the 'spikes' are certain to be
> positive? If not, then instead of sorting on value, one would have to sort on
> absolute value.

Hi Walter,

I agree with you that the problem may be more complicated than described. If those spikes be peaks probably with a noise, than it iis necessary to use another approach. Maybe that the function tolpeak.m omitting all peaks less than a given tolerace could help:
     www.mathworks.com/matlabcentral/fileexchange/22662
or another one from FEX.

Mira

Subject: Finding Maximum Points in an Array

From: Miroslav Balda

Date: 26 Nov, 2010 22:40:05

Message: 8 of 13

"Richard Wylde" <rwylde@gmail.com> wrote in message <icp6nf$r5q$1@fred.mathworks.com>...
> "Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <icp46t$hrd$1@fred.mathworks.com>...
> > "Richard Wylde" <rwylde@gmail.com> wrote in message <icouvv$hgp$1@fred.mathworks.com>...

SNIP

> Thank you. Will this also output the time (or at least number in the array) at which these values occur, or is there a way that I can do this? It's important that I know both the maximum values, and where they occur.
>
> Thanks again,
>
> Richard.

See help sort

Mira

Subject: Finding Maximum Points in an Array

From: Richard Wylde

Date: 27 Nov, 2010 19:31:04

Message: 9 of 13

"Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <icpbh8$4ic$1@fred.mathworks.com>...
> Walter Roberson <roberson@hushmail.com> wrote in message <icp8sv$4ns$1@canopus.cc.umanitoba.ca>...
> > On 10-11-26 02:10 PM, Miroslav Balda wrote:
> > > "Richard Wylde" <rwylde@gmail.com> wrote in message
> > > <icouvv$hgp$1@fred.mathworks.com>...
> >
> > >> I have the following problem: I have a large dataset (over 10,000
> > >> values), which I have plotted. Most of these values are zero (or very
> > >> close to zero). However, there are around 9 'spikes' in the graph - it
> > >> is the value of these that I am interested in. They are not, however,
> > >> all the same value, and occur randomly in time.
> > > Hi Richard,
> >
> > > If your data are in the vector "a", then the commands
> > > b = sort(a,'descend');
> > > x = b(1:9);
> > > give 9 maximum values into x.
> >
> > I cannot tell from the original posting whether the 'spikes' are single points
> > each and the 9 largest are to be returned, or if the 'spikes' each consist of
> > a rise and a drop over several points and it is the location of the highest
> > point of 9 of these rise/drop areas that are to be found ? To use other
> > wording, are the 'spikes' single points, or are they "peaks"?
> >
> > If the 'spikes' are peaks, then the method Miroslav shows is not certain to
> > work, as it is possible (and likely) that a point that is on the rise or fall
> > of a peak but not at the top of the peak, will happen to be greater than the
> > highest point of a different peak.
> >
> >
> > Another point I have to ask is whether the 'spikes' are certain to be
> > positive? If not, then instead of sorting on value, one would have to sort on
> > absolute value.
>
> Hi Walter,
>
> I agree with you that the problem may be more complicated than described. If those spikes be peaks probably with a noise, than it iis necessary to use another approach. Maybe that the function tolpeak.m omitting all peaks less than a given tolerace could help:
> www.mathworks.com/matlabcentral/fileexchange/22662
> or another one from FEX.
>
> Mira

Apologies - I ought to have been more specific. They are most certainly not single points, they are peaks. I'll take a look at tolpeak.m...though another problem is that some peaks are very small, while others are quite big. It is therefore hard to define a tolerance. They are also not all positive - some will be negative (and of similar magnitude).

Richard.

Subject: Finding Maximum Points in an Array

From: Miroslav Balda

Date: 27 Nov, 2010 22:26:03

Message: 10 of 13

"Richard Wylde" <rwylde@gmail.com> wrote in message <icrm9o$m6d$1@fred.mathworks.com>...
> "Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <icpbh8$4ic$1@fred.mathworks.com>...
> > Walter Roberson <roberson@hushmail.com> wrote in message <icp8sv$4ns$1@canopus.cc.umanitoba.ca>...
> > > On 10-11-26 02:10 PM, Miroslav Balda wrote:
> > > > "Richard Wylde" <rwylde@gmail.com> wrote in message
> > > > <icouvv$hgp$1@fred.mathworks.com>...
> > >

SNIP

> Apologies - I ought to have been more specific. They are most certainly not single points, they are peaks. I'll take a look at tolpeak.m...though another problem is that some peaks are very small, while others are quite big. It is therefore hard to define a tolerance. They are also not all positive - some will be negative (and of similar magnitude).
>
> Richard.

Hi Richard,

There is no problem with tolpk function, because it recognises the greatest peak from a cluster applying a relative tolerance to the peak vicinity. Of course that you will have to apply absolute value of your process as the argument.
Good luck.

Mira
 

Subject: Finding Maximum Points in an Array

From: Richard Wylde

Date: 27 Nov, 2010 22:45:04

Message: 11 of 13

"Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <ics0hr$afb$1@fred.mathworks.com>...
> "Richard Wylde" <rwylde@gmail.com> wrote in message <icrm9o$m6d$1@fred.mathworks.com>...
> > "Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <icpbh8$4ic$1@fred.mathworks.com>...
> > > Walter Roberson <roberson@hushmail.com> wrote in message <icp8sv$4ns$1@canopus.cc.umanitoba.ca>...
> > > > On 10-11-26 02:10 PM, Miroslav Balda wrote:
> > > > > "Richard Wylde" <rwylde@gmail.com> wrote in message
> > > > > <icouvv$hgp$1@fred.mathworks.com>...
> > > >
>
> SNIP
>
> > Apologies - I ought to have been more specific. They are most certainly not single points, they are peaks. I'll take a look at tolpeak.m...though another problem is that some peaks are very small, while others are quite big. It is therefore hard to define a tolerance. They are also not all positive - some will be negative (and of similar magnitude).
> >
> > Richard.
>
> Hi Richard,
>
> There is no problem with tolpk function, because it recognises the greatest peak from a cluster applying a relative tolerance to the peak vicinity. Of course that you will have to apply absolute value of your process as the argument.
> Good luck.
>
> Mira
>


Thanks - you're right. I have, however, found http://www.mathworks.com/matlabcentral/fileexchange/25500-peakfinder

to be a better function - it quickly finds the local maximum's across the entire data.


Richard.

Subject: Finding Maximum Points in an Array

From: WOODARD27VIRGINIA

Date: 20 Jan, 2011 21:35:18

Message: 12 of 13

If you are willing to buy a car, you would have to get the <a href="http://bestfinance-blog.com/topics/home-loans">home loans</a>. Furthermore, my father usually utilizes a student loan, which supposes to be really fast.

Subject: Finding Maximum Points in an Array

From: aasim Azooz

Date: 20 Jan, 2011 23:24:05

Message: 13 of 13

"Richard Wylde" wrote in message <icouvv$hgp$1@fred.mathworks.com>...
> Hi there,
>
> I have the following problem: I have a large dataset (over 10,000 values), which I have plotted. Most of these values are zero (or very close to zero). However, there are around 9 'spikes' in the graph - it is the value of these that I am interested in. They are not, however, all the same value, and occur randomly in time.
>
> How can I write a program that will find these values, and output both the value and the time that the value occurs at? I've tried various things, but nothing consistently picks out all points.
>
>
> I appreciate the help.
Do not take the trouble USE MY M-file maxima from the matlab file exchange
Aasim Azooz

Tags for this Thread

No tags are associated with this thread.

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.

Contact us