2015-04-29 56 views
0

在我的GUI中有一个轴,我想添加一个按钮来放大/缩小坐标轴中的绘制信号。但我不知道如何编码这些按钮。任何帮助GUI matlab添加缩放按钮用于缩放轴

+0

你想让自己的按钮或图形工具栏工作吗? – excaza

+0

我想把自己的按钮,我是新的matlab。谢谢 –

+0

这是一个程序化的图形用户界面还是你使用GUIDE? – excaza

回答

0

在图的放大和缩小键已经可以在Figure toolbar 工具栏可以通过图菜单中可见:

View -> Figure Toolbar 

希望这有助于。

0

使用uitoolbar函数创建自定义工具栏。然后,使用uipushtool创建放大和缩小按钮。在按钮的回调函数中,您可以获取当前的轴限制,然后按某个因子对其进行缩放。

1

根据您的评论,我创建了一个快速的小GUI来说明这个过程。

此代码假定你有MATLAB 2014B或更新:

function heyitsaGUI 
% Set up a basic GUI 
h.mainwindow = figure(... % Main figure window 
    'Units','pixels', ... 
    'Position',[100 100 800 800], ... 
    'MenuBar','none', ... 
    'ToolBar','none' ... 
    ); 

h.myaxes = axes(... 
    'Parent', h.mainwindow, ... 
    'Position', [0.1 0.15 0.8 0.8] ... 
    ); 

h.zoomtoggle = uicontrol(... 
    'Style', 'togglebutton', ... 
    'Parent', h.mainwindow, ... 
    'Units', 'Normalized', ... 
    'Position', [0.4 0.05 0.2 0.05], ... 
    'String', 'Toggle Zoom', ... 
    'Callback', {@myzoombutton, h} ... % Pass along the handle structure as well as the default source and eventdata values 
    ); 

% Plot some data 
plot(1:10); 
end 

function myzoombutton(source, ~, h) 
% Callbacks pass 2 arguments by default: the handle of the source and a 
% structure called eventdata. Right now we don't need eventdata so it's 
% ignored. 
% I've also passed the handles structure so we can easily address 
% everything in our GUI 
% Get toggle state: 1 is on, 0 is off 
togglestate = source.Value; 

switch togglestate 
    case 1 
     % Toggle on, turn on zoom 
     zoom(h.myaxes, 'on') 
    case 0 
     % Toggle off, turn off zoom 
     zoom(h.myaxes, 'off') 
end 
end 

将产生你的东西,看起来像这样:

Sample GUI

既然你是新的我会强烈建议您通过MATLAB's GUI building documentation阅读,它引导您使用GUIDE构建编程GUI和GUI。我在这里所做的是创建一个自定义小Callback function,myzoombutton,它允许您为您的轴对象打开和关闭缩放。有几个很好的方法来回答你的问题,这只是一个,不一定是最好的。我喜欢使用这种方法,因为它给了我一个基于切换按钮状态添加其他操作和计算的框架。

看看代码和链接的文档,它应该有望帮助您开始。