Zoom in Zoom out axes with button function

excuse me, i have a question. how to make a button function to zoom in and zoom out an axes ?, please someone help me.

댓글 수: 4

How closely does it need to model the existing zoom behavior? In particular the existing behavior needs to keep track of the entire history of zoom in and out so that the user can "undo" one zoom at a time. It is this tracking that complicates the function.
sorry for late reply. I get code for zooming image in axes and using a slider for zoom in zoom out the image. When i run it, it work fine, but when i put that code to my application, it not work.
this is the code sir :
function varargout = zoomtest(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @zoomtest_OpeningFcn, ...
'gui_OutputFcn', @zoomtest_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
function zoomtest_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 zoomtest (see VARARGIN)
% Choose default command line output for zoomtest
handles.output = hObject;
% Read in standard MATLAB demo image.
grayImage = imread('football.jpg');
axes(handles.axesImage);
imshow(grayImage, []);
title('Original Grayscale Image');
% Set up zoom slider
minZoom = get(handles.sldZoom, 'min')
maxZoom = get(handles.sldZoom, 'max')
set(handles.sldZoom, 'value', minZoom);
% set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
% Update handles structure
guidata(hObject, handles);
function sldZoom_Callback(hObject, eventdata, handles)
% hObject handle to sldZoom (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
zoomFactor = get(hObject,'Value');
axes(handles.axesImage);
zoom('out');
zoom(zoomFactor);
txtInfo = sprintf('Zoom Factor = %.2f (%d %%)\n\nOnce zoomed, you can pan by clicking and dragging in the image.', zoomFactor, round(zoomFactor * 100));
set(handles.txtInfo, 'String', txtInfo);
txtInfo = sprintf('Zoom Factor = %.2f\n\nOnce zoomed, you can pan by clicking and dragging in the image.', zoomFactor);
set(handles.sldZoom, 'TooltipString', txtInfo);
txtZoom = sprintf('Zoom Factor = %.2f (%d %%)', zoomFactor,round(zoomFactor * 100));
set(handles.txtZoom, 'String', txtZoom);
set(handles.axesImage, 'ButtonDownFcn', 'disp(''This executes'')');
set(handles.axesImage, 'Tag', 'DoNotIgnore');
h = pan;
set(h, 'ButtonDownFilter', @myPanCallbackFunction);
set(h, 'Enable', 'on');
return;
function [flag] = myPanCallbackFunction(obj, eventdata)
% If the tag of the object is 'DoNotIgnore', then return true.
% Indicate what the target is
disp(['In myPanCallbackFunction, you clicked on a ' get(obj,'Type') 'object.'])
objTag = get(obj, 'Tag');
if strcmpi(objTag, 'DoNotIgnore')
flag = true;
else
flag = false;
end
return;
% --- Executes during object creation, after setting all properties.
function sldZoom_CreateFcn(hObject, eventdata, handles)
% hObject handle to sldZoom (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
What happens when you try it?
Lidank Abiel
Lidank Abiel 2013년 9월 5일
sorry for late again Mr.walter, but i've found the answer. thank you before :)

댓글을 달려면 로그인하십시오.

답변 (1개)

Sean de Wolski
Sean de Wolski 2013년 9월 5일

0 개 추천

I would just add the predefined ZOOM buttons to the toolbar of the figure. There's no reason to reinvent the wheel.
In GUIDE:
Tools Menu -> Toolbar editor

카테고리

도움말 센터File Exchange에서 Labels and Annotations에 대해 자세히 알아보기

제품

태그

질문:

2013년 9월 1일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by