function uiexample
f = figure('Visible','on');
ax = axes('Units','pixels');
plot(peaks)
xlab = xlabel('x');
ylab = ylabel('y');
set(xlab,'ButtonDownFcn',{@updateplot,ax,1})
set(ylab,'ButtonDownFcn',{@updateplot,ax,2})
infotext = 'click on axis labels to enter new limits';
htext = uicontrol('style','text','string',infotext,...
'position',[0 0 5*numel(infotext) 20])
end
function updateplot(hObject,event,axhandle,XorY)
XLim = axhandle.XLim;
YLim = axhandle.YLim;
name='Input for plot limits';
numlines=1;
switch XorY
case 1
prompt={'Enter Xmin:','Enter Xmax:'};
defaultanswer={num2str(XLim(1)),num2str(XLim(2))};
XLim=cell2mat(inputdlg(prompt,name,numlines,defaultanswer));
axhandle.XLim = str2num(XLim)';
case 2
prompt={'Enter Ymin:','Enter Ymax:'};
defaultanswer={num2str(YLim(1)),num2str(YLim(2))};
YLim=cell2mat(inputdlg(prompt,name,numlines,defaultanswer));
axhandle.YLim = str2num(YLim)';
end
end
Best Answer