MATLAB: How to create a GUI that can zoom into or enlarge a subplot in the GUI in MATLAB 7.6 (R2008a)

enlargeguideMATLABrefreshzoom

I have a GUI with many subplots. When I click on one subplot, I would like to have the graph on that subplot on a small AXIS to be displayed on a large AXIS elsewhere on the same GUI.

Best Answer

To go about this, create a GUI program file and specify the 'ButtonDownFcn' callbacks for each of the small AXIS to redraw the same figure on the large AXIS.
To start, specify the callbacks as follows in the GUI OpeningFcn:
%%Initialization code
% Axes 1 code here
plot(handles.axes1,1:200);
set(handles.axes1,'ButtondownFcn',{@axes1_ButtonDownFcn, handles})
% Axes 2 code here
surf(handles.axes2,peaks(50));
set(handles.axes2,'ButtondownFcn',{@axes2_ButtonDownFcn ,handles})
% Axes 3 code here
axes(handles.axes3), hist(randn(1000));
set(handles.axes3,'ButtondownFcn',{@axes3_ButtonDownFcn, handles})
The code snippet above plots the initial state of each AXIS. To make each AXIS interact upon a user's mouseclick,follow it up by defining a Button Down Function callback for each AXIS, which in turn refreshes the fourth, large AXIS depending on which small AXIS called it. As an example, the following code demonstrates the samefor 'axes1':
% --- Executes on mouse press over axes background.
function axes1_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

axes4_Refresh(handles, 'Axes 1 called')
This function needs to be defined separately for each axes. Finally, the function that actually refreshes the fourth, large axes is defined as follows:
function axes4_Refresh(handles, callingAxes)
% hObject handle to axes3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes4)
switch callingAxes
case 'Axes 1 called'
plot(1:200)
case 'Axes 2 called'
surf(peaks(50))
case 'Axes 3 called'
hist(randn(1000))
otherwise
error('Wrong argument specified to axes4_Refresh')
end