How do I add ActionPostCallback to GUI axes

6 Ansichten (letzte 30 Tage)
Heine Hørup Pedersen
Heine Hørup Pedersen am 14 Mär. 2018
Bearbeitet: Adam am 16 Mär. 2018
Using Matlab 2016b, I have used GUIDE to create a gui containing axes. I want to be able to control the XTick and XTickLabels shown in the plot. Therefore I try to add a callback to the zoom and pan event. During the axes create function I try to add a ActionPostCallback for zoom and pan. This works for the zoom part but it fails in the pan(hObject) part, since hObject is not a figure handle as far as I understand. How can I add a callback to the pan event?
function axes1_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes1
set(zoom(hObject),'ActionPostCallback',@(x,y) XTickLabelCallbackFcn(hObject));
set(pan(hObject),'ActionPostCallback',@(x,y) XTickLabelCallbackFcn(hObject));
Error using uigetmodemanager (line 17) First argument must be a figure handle
Error in getuimode (line 12) hManager = uigetmodemanager(hFig);
Error in pan>locGetMode (line 290) hMode = getuimode(hFig,'Exploration.Pan');
Error in pan>locGetObj (line 220) hMode = locGetMode(hFig);
Error in pan (line 184) out = locGetObj(arg1);

Antworten (1)

Adam
Adam am 14 Mär. 2018
Both zoom and pan should take a figure handle, which, by default, will be
handles.figure1
in a callback (or in the OpeningFcn which is where I usually put such things).
I always rename the tag from 'figure1' to something more sensible, but whatever your tag is for your figure is what would replace 'figure1'
  2 Kommentare
Heine Hørup Pedersen
Heine Hørup Pedersen am 16 Mär. 2018
Is it wrong to assume Axes handles are equivalent to Figure handles? The hObject is a [1x1 Axes]. I can apply a callback on the zoom event , but not the pan event.
Adam
Adam am 16 Mär. 2018
Bearbeitet: Adam am 16 Mär. 2018
axes handles are not at all the same as figure handles. I am surprised you don't get an error with zoom if you are trying to use it with an axes handle.
A figure can contain any number of axes (or none at all) and the zoom function applies to the figure as a whole as the toolbar with the zoom icon is figure-level also. Though I notice in R2018a you can now add toolbars to axes, but they are not supported by having a zoom or pan object per axes so far as I can see.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Specifying Target for Graphics Output 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