I am new to MATLAB, and I have added a logo on the GUI using UIpanel and axes method. But since its an axes over which my image is getting displayed, there is the Zoom(magnifying glass) cursor which I would like to remove but I am unable to. When I created the axes inside the Uipanel, I did not get the createfuncn and callback which usually gets generated automatically, So how should I proceed with it. Thanks in Advance
问题:
回答1:
You can turn off zoom using zoom off
or zoom(f, 'off')
, where f
is a handle to your GUI's figure.
Note that zoom is turned on or off at the level of a figure, not an individual axes, so you cannot straightforwardly have zoom on for one set of axes
回答2:
I've found a possible solution that allows enabling / disabling the zoom for specific selected axes:
The solution consists in using the function:
setAllowAxesZoom
I've created a simple GUI (with "GUIDE") which contains two axes and, for each of them, two pushbuttons to eneble / disable the zoom.
In the figure's OpeningFcn
function I've set zoom off to the left axes:
h=zoom;
setAllowAxesZoom(h,handles.left_axes,false);
When the GUI is run and the zoon tool is selected from the figure's toolbar, it has not effect on the left axes while it has effect on the right axes.
In the pushbuttons callbacks the setAllowAxesZoom
is called to either enable or disable the zoom on the respectives axes.
This is the code of the whole GUI ".m
" file (I do not know how to share also the ".fig
" file (sorry).
function varargout = zoom_on_off(varargin)
% ZOOM_ON_OFF MATLAB code for zoom_on_off.fig
% ZOOM_ON_OFF, by itself, creates a new ZOOM_ON_OFF or raises the existing
% singleton*.
%
% H = ZOOM_ON_OFF returns the handle to a new ZOOM_ON_OFF or the handle to
% the existing singleton*.
%
% ZOOM_ON_OFF('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ZOOM_ON_OFF.M with the given input arguments.
%
% ZOOM_ON_OFF('Property','Value',...) creates a new ZOOM_ON_OFF or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before zoom_on_off_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to zoom_on_off_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help zoom_on_off
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @zoom_on_off_OpeningFcn, ...
'gui_OutputFcn', @zoom_on_off_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before zoom_on_off is made visible.
function zoom_on_off_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to zoom_on_off (see VARARGIN)
% Choose default command line output for zoom_on_off
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes zoom_on_off wait for user response (see UIRESUME)
% uiwait(handles.figure1);
imshow('cubo_cubi.jpg','parent',handles.left_axes)
h=zoom;
setAllowAxesZoom(h,handles.left_axes,false);
plot(handles.right_axes,[0:.1:4*pi],sin(4*[0:.1:4*pi]))
grid(handles.right_axes,'on');
% --- Outputs from this function are returned to the command line.
function varargout = zoom_on_off_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in enable_zoom_left_axes.
function enable_zoom_left_axes_Callback(hObject, eventdata, handles)
% hObject handle to enable_zoom_left_axes (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
h=zoom;
setAllowAxesZoom(h,handles.left_axes,true);
set(handles.disable_zoom_left_axes,'enable','on')
set(handles.enable_zoom_left_axes,'enable','off')
% --- Executes on button press in disable_zoom_left_axes.
function disable_zoom_left_axes_Callback(hObject, eventdata, handles)
% hObject handle to disable_zoom_left_axes (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
h=zoom;
setAllowAxesZoom(h,handles.left_axes,false);
set(handles.disable_zoom_left_axes,'enable','off')
set(handles.enable_zoom_left_axes,'enable','on')
% --- Executes on button press in enable_zoom_right_axes.
function enable_zoom_right_axes_Callback(hObject, eventdata, handles)
% hObject handle to enable_zoom_right_axes (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
h=zoom;
setAllowAxesZoom(h,handles.right_axes,true);
set(handles.disable_zoom_right_axes,'enable','on')
set(handles.enable_zoom_right_axes,'enable','off')
% --- Executes on button press in disable_zoom_right_axes.
function disable_zoom_right_axes_Callback(hObject, eventdata, handles)
% hObject handle to disable_zoom_right_axes (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
h=zoom;
setAllowAxesZoom(h,handles.right_axes,false);
set(handles.disable_zoom_right_axes,'enable','off')
set(handles.enable_zoom_right_axes,'enable','on')
In the next pictures, some snapshots of the GUI whit the zoom enabled / disabled (picture of Juppiter taken from "Jupiter New Horizons" di NASA/Johns Hopkins University Applied Physics Laboratory/Southwest Research Institute - National Aeronautics and Space Administration. Con licenza Pubblico dominio tramite Wikimedia Commons - http://commons.wikimedia.org/wiki/File:Jupiter_New_Horizons.jpg#/media/File:Jupiter_New_Horizons.jpg)
1) the GUI as just opened: zoom tool selected, disabled on left axes, enabled on right axes
2) zoom on right axes
3) "Enable zoom on left axes" pushbutton pressed, zoom of the picture
(*) Pushbuttons are enabled / disabled too.
Hope this helps.