From: Walter Roberson on
TideMan wrote:
> On Aug 5, 8:38 am, Walter Roberson <rober...(a)hushmail.com> wrote:
>> TideMan wrote:
>>> On Aug 5, 4:32 am, "Lim Sim Yee" <cherry90_mugsy...(a)hotmail.com>
>>> wrote:
>>>> i finally understand the whole thing!!
>>>> here's how i did it.
>>>> Zmax = max(max(Z));
>>>> kmax = find(Z==Zmax);
>>>> P = [X(kmax), Y(kmax)]
>>>> hold on;
>>>> plot(X(kmax), Y(kmax), 'xr');
>>>> YAY!
>>>> thank you guys for ya help!
>>> Well, you are lucky that this worked:
>>>> Zmax = max(max(Z));
>>>> kmax = find(Z==Zmax);
>>> because in floating point operations, one thing is rarely exactly
>>> equal to another.
>>> But you don't need to do that. Use the second output argument of max
>>> instead:
>>> [Zmax,kmax]=max(Z(:));
>> There is a difference in the two if there are multiple locations at which the
>> maximum is obtained. Using the two-output max() call will only return the
>> first of the locations; the plot() call the original poster used will draw
>> markers at all of the maxima (but probably in that case, scatter() would be a
>> better plotting call.)
>
> No, he used max(max(Z)), so he got only one maximum
>

But then he does the find(Z==Zmax) so if there are multiple places that have
that maximum value, the find() would return a vector of indices.
From: TideMan on
On Aug 5, 9:38 am, Walter Roberson <rober...(a)hushmail.com> wrote:
> TideMan wrote:
> > On Aug 5, 8:38 am, Walter Roberson <rober...(a)hushmail.com> wrote:
> >> TideMan wrote:
> >>> On Aug 5, 4:32 am, "Lim Sim Yee" <cherry90_mugsy...(a)hotmail.com>
> >>> wrote:
> >>>> i finally understand the whole thing!!
> >>>> here's how i did it.
> >>>> Zmax = max(max(Z));
> >>>> kmax = find(Z==Zmax);
> >>>> P = [X(kmax), Y(kmax)]
> >>>> hold on;
> >>>> plot(X(kmax), Y(kmax), 'xr');
> >>>> YAY!
> >>>> thank you guys for ya help!
> >>> Well, you are lucky that this worked:
> >>>> Zmax = max(max(Z));
> >>>> kmax = find(Z==Zmax);
> >>> because in floating point operations, one thing is rarely exactly
> >>> equal to another.
> >>> But you don't need to do that.  Use the second output argument of max
> >>> instead:
> >>> [Zmax,kmax]=max(Z(:));
> >> There is a difference in the two if there are multiple locations at which the
> >> maximum is obtained. Using the two-output max() call will only return the
> >> first of the locations; the plot() call the original poster used will draw
> >> markers at all of the maxima (but probably in that case, scatter() would be a
> >> better plotting call.)
>
> > No, he used max(max(Z)), so he got only one maximum
>
> But then he does the find(Z==Zmax) so if there are multiple places that have
> that maximum value, the find() would return a vector of indices.

In which case he should do:
find(abs(Z-Zmax) < tol)
where tol is a small number that depends on the magnitudes of Z.