Home > Archive > Matlab > April 2005 > finding local maximum
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
finding local maximum
|
|
| John Vickers 2005-04-22, 9:00 pm |
| Does anyone know how to return the location of a known number of
maximum in a 2d array. In other words, I have a 2d plot of
experimental data and I need to retrieve the x,y coordinates of the
maximum. Any ideas?
John Vickers
| |
| Michael Robbins 2005-04-22, 9:00 pm |
| John Vickers wrote:
>
>
> Does anyone know how to return the location of a known number of
> maximum in a 2d array. In other words, I have a 2d plot of
> experimental data and I need to retrieve the x,y coordinates of the
> maximum. Any ideas?
>
> John Vickers
HELP MAX
[i,j]=find(Z==max(max(Z)))
| |
| John Vickers 2005-04-22, 9:00 pm |
| Thanks for the quick reply, but this only returns the max values if
they are all equal. I need to find the local maximums of experimental
data, where the maximums vary.
Thanks
John Vickers
| |
| Roger Stafford 2005-04-23, 3:59 am |
| In article <ef03b7f.1@webx.raydaftYaTP>, "John Vickers"
<johnvickers@yahoo.com> wrote:
> Thanks for the quick reply, but this only returns the max values if
> they are all equal. I need to find the local maximums of experimental
> data, where the maximums vary.
>
> Thanks
>
> John Vickers
--------
Hi John,
To find your local maxima, you'll have to decide just how local a maxima
is to be. In the continuous domain there is no problem, but with the
discrete data of a matrix, locality needs to be defined. A point could be
considered a local maxima if it is greater than its four nearest
neighbors, or perhaps including also the four nearby diagonals. Or
perhaps even farther afield.
Let X be your data matrix. If you are using just the four nearest
points, you could do this:
[m,n] = size(X);
X0 = X(2:m-1,2:n-1); % The interior points
X1 = X(1:m-2,2:n-1); X2 = X(3:m,2:n-1); % Their two column neighbors
X3 = X(2:m-1,1:n-2); X4 = X(2:m-1,3:n); % Their two row neighbors
[i,j] = find((X1<X0) & (X2<X0) & (X3<X0) & (X4<X0)); % A local maxima
i = i + 1; j = j + 1; % Correct for offset
That should give you the pairs of indices in X where this kind of local
maxima occurs. You might want to vary the above to include maxima
occurring along the edges or at corners. It should be easy to generalize
from this for different notions of locality.
(Remove "xyzzy" and ".invalid" to send me email.)
Roger Stafford
|
|
|
|
|