MATLAB: Can contourplot plot based on the peaks of the function

contourplot

Hi,
I need to plot a contourplot based on the peaks of my function. I know the maximum of my function but the contourplot maximum is different than that. I need to plot something like the below fig. (the data in 2 figures are not the same)
q1.jpg
but I get this one in which, the real peak and the contour peak are not the same. Is there any command for edditing this?
q2.jpg
Thank.

Best Answer

I suspect there is an error in your code. Here's a simple example using the peaks funciton in MATLAB
[x,y,z] = peaks(100);
surf(x,y,z)
view(2)
figure
contour(x,y,z,20)
Here is what the peak function would look like from the top down (view(2))
And here is what the corresponding contour plot looks like. Notice that the peaks align.