我是MATLAB的新手,我使用UIpanel和axes方法在GUI上添加了一个徽标。但是由于它是一个显示我的图像的轴,有一个我想要删除的缩放(放大镜)光标,但我无法。当我在Uipanel中创建轴时,我没有得到通常自动生成的createfuncn和callback,那么我该如何处理呢。 在此先感谢
答案 0 :(得分:1)
您可以使用zoom off
或zoom(f, 'off')
关闭缩放,其中f
是GUI图形的句柄。
请注意,在图形的水平上打开或关闭缩放,而不是单个轴,因此您无法直接对一组轴进行缩放
答案 1 :(得分:0)
我找到了一个可能的解决方案,允许启用/禁用特定选定轴的缩放:
解决方案包括使用函数:
setAllowAxesZoom
我已经创建了一个简单的GUI(带有“GUIDE”),它包含两个轴,并且每个轴都有两个按钮来启用/禁用缩放。
在图的OpeningFcn
功能中,我将缩放设置为左轴:
h=zoom;
setAllowAxesZoom(h,handles.left_axes,false);
当运行GUI并从图形工具栏中选择zoon工具时,它对左轴没有影响,同时它对右轴产生影响。
在按钮回调中,调用setAllowAxesZoom
以启用或禁用相应轴上的缩放。
这是整个GUI“.m
”文件的代码(我不知道如何共享“.fig
”文件(抱歉)。
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')
在接下来的图片中,GUI的一些快照启用/禁用了缩放功能(Juppiter的图片取自“美国宇航局/约翰斯·霍普金斯大学应用物理实验室/西南研究所 - 美国国家航空航天局”的“Jupiter New Horizons”)。 Conmitsza Pubblico dominio tramite Wikimedia Commons - http://commons.wikimedia.org/wiki/File:Jupiter_New_Horizons.jpg#/media/File:Jupiter_New_Horizons.jpg)
1)刚打开的GUI:选择缩放工具,左轴禁用,右轴启用
2)放大右轴
3)“启用左轴缩放”按下按钮,缩放图片
(*)按钮也被启用/禁用。
希望这有帮助。