Use the below code,
hobj = figure;
handles=guihandles(hobj); %Create structure of handles
[x,y] = meshgrid(1:15,1:15);
tri = delaunay(x,y);
z = peaks(15);
P1=trisurf(tri,x,y,z);
Ax=gca;
handles.P1=P1;
handles.Ax=Ax;
hobj.WindowButtonDownFcn=@getPoint;
guidata(hobj,handles); %save the structure
function getPoint(hobj,eventdata)
handles = guidata(hobj); %returns previously stored data
Ax=handles.Ax;
Ax.CurrentPoint
end
This will work without any error. You have to use CurrentPoint property of Axes. Although, I am not sure what you are trying to achieve in the below line,
>> set(handles.text4,'string', num2str(x));