This example will show the following
A simple GUI is created as shown below Magnification & visual inspection (click on image for animated gif). The magnified image can also be moved to another location in the figure, so you can see the original data and the magnified data, see image below. Interactive zooming of data The x and or y axis can be zoomed by the user clicking on the axes limits to zoom in - left sets min, right max and middle click auto scale. function [hTab] = example6 ( ) hFig = dialog ( 'windowstyle', 'normal', 'name', 'Matpi Website Example 6', 'resize', 'on' ); % initialise the main GUI (this allows the left and right tabs to be resizeable [hTab, hFig] = Tab ( 'initialise', 'Main Tab', hFig, [0 0 1 1], 'buttonHeight', 0 );
% Create the 1st page Tab ( 'addtab', hTab, 'Page 1' )
% store data in the GUI Tab ( 'addData', hTab, 'x', 0:0.02:10*pi );
% Add a axes with smart interaction Tab ( 'axes_smart', hTab, 'Page 1', 'myAxes', 'position', [0.1 0.4 0.8 0.5], 'ylim', [-1 1] );
% Create a listbox adding a callback Tab ( 'listbox', hTab, 'Page 1', 'myList', 'position', [0.1 0.1 0.4 0.2], ... 'string', { 'cos' 'sin' 'tan' }, 'Callback', @(a,b)ChangeList ( hTab ) ); % Run Callback to update the plot ChangeList ( hTab ); end function ChangeList ( hTab ) % Get the axes handle and clear it. ax = Tab ( 'handle', hTab, 'Page 1', 'myAxes' ); cla(ax); % Retrieve the data we stored in the GUI earlier. x = Tab ( 'getData', hTab, 'x' ); % Generate some noise to add to the plot noise = rand(1, length(x))./10; % Switch on the selected item in the listbox. switch Tab ( 'get', hTab, 'Page 1', 'myList', 'selectedString' ); case 'cos' % Note turning off the HitTest is not a requirement of smartAxes - it just makes in easier. plot ( ax, x, cos ( x ) + noise, 'HitTest', 'off' ); case 'sin' plot ( ax, x, sin ( x ) + noise, 'HitTest', 'off' ); case 'tan' plot ( ax, x, tan ( x ) + noise, 'HitTest', 'off' ); end end |
Matlab GUI Toolbox >