I have a gui and i want to have 4 buttons to pan my graph so one that goes left right up and down, how would i do this?

2 ビュー (過去 30 日間)
I have a gui and i want to have 4 buttons to pan my graph so one that goes left right up and down, how would i do this?

採用された回答

Matthew Eicholtz
Matthew Eicholtz 2017 年 5 月 3 日
The easy answer: I would suggest using the built-in pan tool in the figure toolbar.
The slightly more complicated answer: Try adapting the following code to your GUI. Here, I am creating a plot of some random numbers and using 4 uicontrols for pan buttons.
function panfigure()
% Setup figure
figure;
plot(rand(10,1),rand(10,1));
ax = gca;
set(ax,...
'Units','pixels',...
'Position',[140 100 400 300],...
'XLimMode','manual',...
'YLimMode','manual');
% Create pushbuttons for panning
uicontrol('Style','pushbutton','Position',[20 40 40 20],'String','Left','Callback',{@panleft,ax});
uicontrol('Style','pushbutton','Position',[100 40 40 20],'String','Right','Callback',{@panright,ax});
uicontrol('Style','pushbutton','Position',[60 60 40 20],'String','Up','Callback',{@panup,ax});
uicontrol('Style','pushbutton','Position',[60 20 40 20],'String','Down','Callback',{@pandown,ax});
end
% Callback functions
function panleft(obj,evt,ax)
dx = diff(ax.XLim);
ax.XLim = ax.XLim-0.05*dx;
end
function panright(obj,evt,ax)
dx = diff(ax.XLim);
ax.XLim = ax.XLim+0.05*dx;
end
function panup(obj,evt,ax)
dy = diff(ax.YLim);
ax.YLim = ax.YLim-0.05*dy;
end
function pandown(obj,evt,ax)
dy = diff(ax.YLim);
ax.YLim = ax.YLim+0.05*dy;
end
Does that help?
  4 件のコメント
Matthew Eicholtz
Matthew Eicholtz 2017 年 5 月 5 日
Copy and paste the entirety of my code into a new file, save, and run it. It should not give any error. Once you see how the buttons work, you can insert them in your code appropriately.
Matthew Eicholtz
Matthew Eicholtz 2017 年 5 月 5 日
I think you received that error because you copied the middle part of the code (that includes an "end" statement), but not the function header. Is that correct?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Objects についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by