Finding X Y coordinates from surface plot

12 views (last 30 days)
Hi All, n00b to MatLab and I have a question that is giving me fits!
peaks is a built-in example function of two variables in MatLab. You can see what peaks looks like with surf(peaks).
Using MatLab, what is the maximum value of peaks (i.e., the maximum z value)?
This one I understand. I use Z = peaks; then max (max(Z)) to get the answer. No problem!
Using MatLab, what is the x, y coordinate of the maximum value?
This is my frustrating issue!
My prof assigned this but hasn't returned a response to my email and I'd like to get this done ASAP. Any advice would be appreciated!

Accepted Answer

Paulo Silva
Paulo Silva on 20 Apr 2011
[X,Y,Z] = peaks;
I=find(Z==max(max(Z)));
X(I); %x values corresponding to the points where Z is maximum
Y(I); %y values corresponding to the points where Z is maximum
To test if values are correct do
[X,Y,Z] = peaks;
surf(X,Y,Z)
hold on
I=find(Z==max(max(Z)));
plot3(X(I),Y(I),Z(I),'x')
  3 Comments
Paulo Silva
Paulo Silva on 20 Apr 2011
She's just being a good teacher, by searching and trying to do the homework you always learn something.
Ilias Iord
Ilias Iord on 9 Apr 2017
This is very helpful indeed, but I am looking for one step further:
I have two vectors of co-ordinates (1-n) for X and Y and a surface (S) with n-n corresponding values.
The question is, how can I get the X, Y values for the single minimum value of S. Because S is n-n, the above solution does not work.
%calculation of drawdown in confined aquifer
clear
clc
% Parameter and variable values
xabs=3000;
yabs=xabs;
xmin=-xabs;
ymin=-yabs;
x=xmin:50:xabs;
y=ymin:50:yabs;
x1=1500;
y1=600;
x2=700;
y2=1800;
x3=1200;
y3=900;
x4=500;
y4=800;
rw=0.3; %well radius
rinf1=2000; %m radius of influence
rinf2=3000;
rinf3=5000;
rinf4=500;
k=2.58; %m/day
q1=1200; %m3/day
q2=1500;
q3=2000;
q4=500;
a=45; % m (confined aquifer width)
hw=30; %m ( well drawdown depth)
s1=drawdown(xabs,x1,y1,rinf1,k,q1,a);
s2=drawdown(xabs,x2,y2,rinf2,k,q2,a);
s3=drawdown(xabs,x3,y3,rinf3,k,q3,a);
s4=drawdown(xabs,x4,y4,rinf4,k,q4,a);
s=s1+s2+s3+s4;
"Drawdown" is the function that calculates S for the well data I need the coordinates for the minimum peak.
Thanks a lot guys!

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!