MATLAB: How to get the value for x and y in the 3D plot for a max z

find x and y value.

I have the following code.
%%
E=200e9; I=7.999e-5; K=-1/(E*I); x=[0:0.1:25]; vv=[];
for i=0:0.1:25
B=[ 0 0 0 0 0 0 0 1 ;
125/6 0 0 0 0 0 5 1 ;
500/3 125/6 0 0 0 0 10 1 ;
1125/2 500/3 125/6 0 0 0 15 1 ;
4000/3 1125/2 500/3 125/6 0 0 20 1 ;
15625/6 4000/3 1125/2 500/3 125/6 0 25 1 ;
1 1 1 1 1 1 0 0 ;
25 20 15 10 5 0 0 0 ];
c=[0 ; (98100./6).*(max(5-i,0)).^3 ; (98100./6).*(max(10-i,0)).^3 ; (98100./6).*(max(15-i,0)).^3 ; (98100./6).*(max(20-i,0)).^3 ; (98100./6).*(max(25-i,0)).^3 ; 98100 ; 98100.*(25-i)];
z=B\c;
% The Values of all of the Reaction Forces and Integration Constants are as follows:
Ra = z(1);
Rb = z(2);
Rc = z(3);
Rd = z(4);
Re = z(5);
Rf = z(6);
C1 = z(7); % Integration Constand

C2 = z(8); % Integration Constand
V=K.*(Ra.*((max(x,0)).^3)./6+Rb.*((max(x-5,0)).^3)./6+Rc.*((max(x-10,0)).^3)./6+Rd.*((max(x-15,0)).^3)./6+Re.*((max(x-20,0)).^3)./6-98100.*(((max(x-i,0))).^3)./6 + C1.*x + C2);
vv=[vv;V];
end
p=[0:0.1:25];
% Generate coordinate pairs [X,P]=meshgrid(x,p); figure(100) surf(X,P,vv);
% % Evaluate function on grid
% Plot surface shading interp; hold on xlabel('Beam Length (m)') ylabel('Crane Position (m)') zlabel('Deflection (m)') hold off
[Zmax,Idx] = max(vv(:)) [ZmaxRow,ZmaxCol] = ind2sub(size(vv), Idx)
%%
I need the x and y value for a specific max z. How do I get it? I have the position in the matrix for the max z but not the value of x and y at that max z. then how doe you find 2 * max z values if your plot shows two values?
Please help me if you can?

Best Answer

clc; clear all ;
[X,Y,Z] = peaks(25) ;
[val,idx] = max(Z(:)) ; % get maximum in Z
x = X(idx) ; % get x for zmax
y = Y(idx) ; % get y for zmax
surf(X,Y,Z) ;
hold on
plot3(x,y,val,'*r') ;
Related Question