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?

1 Ansicht (letzte 30 Tage)
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?

Akzeptierte Antwort

Matthew Eicholtz
Matthew Eicholtz am 3 Mai 2017
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 Kommentare
Matthew Eicholtz
Matthew Eicholtz am 5 Mai 2017
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 am 5 Mai 2017
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?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Dialog Boxes finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by