From: TideMan on
On Aug 2, 8:18 pm, "Lim Sim Yee" <cherry90_mugsy...(a)hotmail.com>
wrote:
> > Describe in words what the C and h return values from contourf
> > represent. What size is each of them expected to be? Are they expected
> > to have the same number of rows such that [C,h] would be computationally
> > valid? Considering what you want to find out, is it necessary to examine
> > the values in both? max() by default finds the maximum of each column:
> > is that what you want to do?
>
> The loaded data will be an array of 243-by-81 matrix. It is separated to to 81x81 square matrices. the first matrix which is X is called from row 1 to row 82, second matrix Y is called from row 82 to 162 and the remaining rows  is Z.
>
>
>
> > Are you trying to find the maximum contour level, or are you trying to
> > find the peak value? If you are trying to find the peak value, would it
> > not make more sense to examine the Z values directly instead of the
> > results of contouring ?
>
> I am required to plot a filled contour plot of the data with 10 level. The data are X, Y and Z.
> And then find the highest point in the contour and mark it with a red 'x' in the filled-contour plot.
>  My tutor said it involves 'max' command. Its not peak.

So, as Walter asked you, why did you do this:
M = max([C,h]);
and not this:
[M,imx]=max(Z(:));

Now, M is the maximum height, but how can you plot M, which is the
height, on a horizontal grid?
You cannot.
You need to plot the x and y position of the maximum using the index
imx.
And before you plot it, you need to hold on, otherwise you will not
see the contour beneath.

My impression from your questions is that you do not understand what a
contour plot is.
You need to work on this, otherwise you are never going to get this
homework done.


From: Lim Sim Yee on
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!
From: TideMan on
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(:));
From: Walter Roberson on
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.)
From: TideMan on
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