Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Zoom ActionPostCallback help

464 views
Skip to first unread message

Mike

unread,
May 24, 2007, 10:47:29 AM5/24/07
to
i hope that someone can help me with this as i am getting pretty
annoyed with it.
i am trying to get the new X and Y limits of the axes that i am
zooming into and put those values as a string into a edit box in a
GUI, i am using zoom and ActionPostCallback pretty much as the help
file

set(h,'ActionPreCallback',@myprecallback);
set(h,'ActionPostCallback',@mypostcallback);
set(h,'Enable','on');
%
function myprecallback(obj,evd)
disp('A zoom is about to occur.');
%
function mypostcallback(obj,evd)
newLim = get(evd.Axes,'XLim');
msgbox(sprintf('The new X-Limits are [%.2f %.2f].',newLim));

however i am adding the line, under the function ActionPostCallback

set(handles.TH_X_max,'string',num2str(newLim(2)));

handles.TH_X_max is my edit box,
using this line i get the error, and indeed i get the error when i
try to set anything using the handles structure to referance to a GUI
object.

Warning: An error occurred during the mode callback.
In uitools.uimode.fireActionPostCallback at 14
In zoom>local2DButtonUpFcn at 1164
In hgfeval at 63
In uitools.uimode.modeWindowButtonUpFcn at 27
In uitools.uimode.setCallbackFcn>localModeWindowButtonUpFcn at 34

this error seems more to do with matlab than my actual code, can
anyone shed any light of what is causing this error and how i can get
over it as it is way over my head!
Cheers
Mike

Yair Altman

unread,
May 24, 2007, 12:31:41 PM5/24/07
to
try modifying mypostcallback to mypostcallback(varargin) and place a
breakpoint on its first line, to see why calling this function causes
an error (the varargin change ensured that this is not due to missing
parameters definition).

Also, you can always do "dbstop if error" to see where the problem is
and why.

Yair Altman

mike

unread,
May 25, 2007, 5:31:30 AM5/25/07
to
i have used 'dbstop if warning' and the code stops in
fireActionCallback.m

function fireActionPreCallback(hThis,evd)
%Execute the ActionPreCallback callback

% Copyright 2006 The MathWorks, Inc.

hFig = hThis.FigureHandle;
blockState = hThis.Blocking;
hThis.Blocking = true;
try
if ~isempty(hThis.ActionPreCallback)
hgfeval(hThis.ActionPreCallback,hFig,evd);
end
catch
warning('MATLAB:uitools:uimode:callbackerror',...
'An error occurred during the mode callback.');
end
hThis.Blocking = blockState;

so from this code it looks like my hThis.ActionPreCallback is empty,
however i really don't know why!
Mike

Steven Lord

unread,
May 25, 2007, 9:11:48 AM5/25/07
to

"mike" <bigmi...@hotmail.com> wrote in message
news:ef57...@webcrossing.raydaftYaTP...

If the warning message you received was 'An error occurred during the mode
callback.', then most likely your ActionPreCallback threw an error. [The
only way in this block of code to reach that warning is for the TRY block to
have errored.]

Use LASTERROR to determine what error it threw after DBSTOP IF WARNING stops
execution and fix that error.

--
Steve Lord
sl...@mathworks.com


Mike

unread,
May 25, 2007, 9:38:59 AM5/25/07
to
"Use LASTERROR to determine what error it threw after DBSTOP IF
WARNING stops execution and fix that error."

o.k using lasterror, i get this

message: 'Reference to non-existent field 'TH_X_max'.'
identifier: 'MATLAB:nonExistentField'
stack: [7x1 struct]

i assume that the line

"set(handles.TH_X_max,'string',num2str(max_value));"

is causing a problem, especially handles.TH_X_max
is this because this handles structure is not being past to the
"mypostcallback(obj,handles)" function?
if this is the case how can i pass the handle structure that points
to my editbox (TH_X_max)?
Cheers
Mike

Walter Roberson

unread,
May 25, 2007, 11:46:10 AM5/25/07
to
In article <ef57...@webcrossing.raydaftYaTP>,
Mike <bigmi...@hotmail.com> wrote:

>o.k using lasterror, i get this

>message: 'Reference to non-existent field 'TH_X_max'.'
>identifier: 'MATLAB:nonExistentField'
>stack: [7x1 struct]

>i assume that the line

>"set(handles.TH_X_max,'string',num2str(max_value));"

>is causing a problem, especially handles.TH_X_max
>is this because this handles structure is not being past to the
>"mypostcallback(obj,handles)" function?

You defined the callback for the post action as just @mypostcallback
Therefore what you will get passed to mypostcallback is just
the two implicit parameters, obj and event_obj -- see the zoom()
documentation on this point.

If you want additional parameters such as your handles passed to
the callback, you have to pass them at the time you construct the
callback:

h = zoom(figure_handle);
set(h, 'ActionPostCallback', {@mypostcallback, handles});
--
There are some ideas so wrong that only a very intelligent person
could believe in them. -- George Orwell

Steven Lord

unread,
May 25, 2007, 5:12:09 PM5/25/07
to

"Mike" <bigmi...@hotmail.com> wrote in message
news:ef57...@webcrossing.raydaftYaTP...

Take a look back at the code you posted in your original post:


> set(h,'ActionPreCallback',@myprecallback);
> set(h,'ActionPostCallback',@mypostcallback);
> set(h,'Enable','on');
> %
> function myprecallback(obj,evd)
> disp('A zoom is about to occur.');
> %
> function mypostcallback(obj,evd)
> newLim = get(evd.Axes,'XLim');
> msgbox(sprintf('The new X-Limits are [%.2f %.2f].',newLim));
>
> however i am adding the line, under the function ActionPostCallback
>
> set(handles.TH_X_max,'string',num2str(newLim(2)));


What are the inputs to the function you specify as the ActionPreCallback
(both in general and for this specific example)?

http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/ref/zoom.html

Can you find a way to get the GUI HANDLES for your figure from those inputs?

--
Steve Lord
sl...@mathworks.com


Mike

unread,
May 29, 2007, 9:38:40 AM5/29/07
to
> What are the inputs to the function you specify as the
> ActionPreCallback
> (both in general and for this specific example)?
>
Can you find a way to get the GUI HANDLES for your figure from
> those inputs?
>

h is the handle of the zoom of a particular axis in the GUI
(h=zoom(handles.Time_history)), it appears that my handles structure
is not being passed onto the function, usually in a function to pass
data you would type

mytestfuction(data)

function mytestfuction(data)

however it looks like there is no way to pass data this way to the
mypostcallback function as this function is called automatically by
the zoom command in the GUI rather than a user in the M-file, unless
i am missing something
any ideas

Steven Lord

unread,
May 29, 2007, 12:55:58 PM5/29/07
to

"Mike" <bigmi...@hotmail.com> wrote in message
news:ef57...@webcrossing.raydaftYaTP...
>> What are the inputs to the function you specify as the
>> ActionPreCallback
>> (both in general and for this specific example)?
>>
> Can you find a way to get the GUI HANDLES for your figure from
>> those inputs?
>>
>
> h is the handle of the zoom of a particular axis in the GUI
> (h=zoom(handles.Time_history)),

Neither your original code nor the example given in the reference page for
ZOOM use the variable h.

> it appears that my handles structure
> is not being passed onto the function, usually in a function to pass
> data you would type
>
> mytestfuction(data)
>
> function mytestfuction(data)

Correct.

> however it looks like there is no way to pass data this way to the
> mypostcallback function as this function is called automatically by
> the zoom command in the GUI rather than a user in the M-file, unless
> i am missing something
> any ideas

Quoting your original code again:

> set(h,'ActionPreCallback',@myprecallback);
> set(h,'ActionPostCallback',@mypostcallback);
> set(h,'Enable','on');
> %
> function myprecallback(obj,evd)
> disp('A zoom is about to occur.');
> %
> function mypostcallback(obj,evd)
> newLim = get(evd.Axes,'XLim');
> msgbox(sprintf('The new X-Limits are [%.2f %.2f].',newLim));
>
> however i am adding the line, under the function ActionPostCallback
>
> set(handles.TH_X_max,'string',num2str(newLim(2)));

What are the actual input arguments to the function you are specifying as
the ActionPreCallback? [You don't need to look at anything except this post
to answer this question.]

Is one of those input arguments a struct array named handles? [Again, this
posting contains all the information you need to answer.]

Looking at the reference page for ZOOM, what do those input arguments to the
function you specified as the ActionPreCallback function represent?

Is there a way, possibly using the GUIHANDLES function, to obtain a struct
array named handles (containing the handles for the objects in your GUI)
given those input arguments to your myprecallback function?

--
Steve Lord
sl...@mathworks.com


Mike

unread,
May 31, 2007, 11:16:47 AM5/31/07
to
Excellent i have got it to work with the GUIHANDLES function! that
may not be the slickest way but it works, i've never come across that
function before
thanks for all your help!
Mike

Olivier

unread,
Jun 10, 2011, 12:13:05 PM6/10/11
to
Mike <Bigmi...@hotmail.com> wrote in message <ef57...@webcrossing.raydaftYaTP>...

Mike, Steve,
I am confronted to the same problem and cannot solve it even with the use of the GUIHANDLES function.
If I use handles = guihandles in the body of the function creating the figure in the main GUI, the result does not have all the handles of the main GUI and therefore other callbacks stop working afterwards.
If I use the guihandles inside the postActioncallback, I get the usual warning message (similar to Mike's) and the action is not performed.
Mike, any detail on how you made it work?
Steve, any idea on how to use guihandles to make it work?

Olivier

Jan Klement

unread,
Aug 23, 2012, 10:33:07 AM8/23/12
to
Maybe this code will help you
In your mainGUI when creating a new figure:
---------------------------------------------
handles.plot_fig=figure;
h = zoom(handles.plot_fig);
set(h,'ActionPostCallback',@zoom_callback);
fig_hand=guidata(handles.plot_fig);

fig_hand.calling_gui=hObject;
guidata(handles.plot_fig,fig_hand); % save the handle of the main GUI into the handels structure of the figure
---------------------------------------------
And here the function:
---------------------------------------------
function zoom_callback(obj, evd)
lim_xachse = get(evd.Axes,'XLim');
lim_yachse = get(evd.Axes,'YLim');
h=guidata(obj);
h_main=guidata(h.calling_gui); %get the handels stucture of the main gui
set(h_main.edit4,'String',num2str(lim_xachse(1))); % the main GUI has to contain an edit1 and 4
set(h_main.edit1,'String',num2str(lim_xachse(2)));
---------------------------------------------
0 new messages