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
Also, you can always do "dbstop if error" to see where the problem is
and why.
Yair Altman
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
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
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
>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
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)?
Can you find a way to get the GUI HANDLES for your figure from those inputs?
--
Steve Lord
sl...@mathworks.com
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
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, 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