"Warning: Error during Mode Callback" when calling functions in Zoom ActionPostCallback

8 次查看(过去 30 天)
Right now I am working with a Matlab GUI that plots data from an external file. I have recently added in the default toolbar zoom feature. I have modified the zoom by having it take the new x limits of the graph that has been zoomed in on and setting these limits as the new time limits for a separate graph (a smith chart). The new limits are assigned during the actionpostcallback function. I have also created a pushbutton callback function that redraws the smith chart with the new x limits from when the zoom occurs. This function works perfectly when called on its own using the button. However, when I try calling this function during the actionpostcallback of the zoom I receive the error:
Warning: An error occurred during the mode callback.
> In uitools.uimode.fireActionPostCallback at 14
In zoom>local2DButtonUpFcn at 1346
In hgfeval at 63
In uitools.uimode.modeWindowButtonUpFcn at 46
In uitools.uimode.setCallbackFcn>localModeWindowButtonUpFcn at 54
All of these files are default Matlab files. Here is my code for the zoom function:
% ---this function turns on the use of the default zoom feature
function toolbar_zoomin_OnCallback(hObject, eventdata, handles)
% hObject handle to toolbar_zoomin (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global zoom_use; %this variable is used in the redrawsmithchart function
zoom_use=0;
%handles.del_pwr and handles.gmag are the handle names for the two graphs that can be zoomed in on. handles.smithchart is the handle of the graph that will be having its limits resized. handles.rstart and handles.rend (used in the redrawsmithchart function) are the numbers of the first and last points of the plotted smith chart and the two graphs.
h = zoom(handles.del_pwr);
h = zoom(handles.gmag);
set(h,'ActionPostCallback',@mypostcallback);
set(h,'Enable','on');
% ---occurs after mouse button up for zoom function
function mypostcallback(obj,evd)
global newLim zoom_use; % newLim is used to find the new x limits of the zoomed area.
newLim = get(evd.Axes,'XLim');
disp(sprintf('The new X-Limits are [%.2f %.2f].',newLim));
zoom_use =1;
axis 'auto y'; % autoscales the y axis to fit the window for the zoomed graph.
pushbutton_redrawsmithchart_Callback(hObject, eventdata, handles) % <-----This is the function that when called, produces the warning message. Commenting out this line removes the error but obviously stops the task from being performed.
This is the code for the redrawsmithchart function:
% --- Executes on button press in pushbutton_redrawsmithchart redraws the smith chart with the new limits acquired during the postcallback.
function pushbutton_redrawsmithchart_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_redrawsmithchart (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global newLim zoom_use ;
% the following two lines gather the data from the source
PortList = handles.colheaders;
[~,DataCount]=size(PortList);
if zoom_use==1;
disp(newLim);
tstart = newLim(1); % sets the start and stop times (the x min and max)
tstop = newLim(2);
This function then continues through the process of plotting a smith chart in Matlab within the if statement. I have not included that process as it is lengthy and I do not believe it is causing the problem. I can post the rest of that code if it is needed.
I am not sure as to why the function redrawsmithchart would work on its own but would create errors when called in another fuction. Thank you for any help.

采纳的回答

Matthew
Matthew 2013-10-16
I have found a work around for this bug. By using a while loop and the uiwait, uiresume commands I was able to get the graphs to redraw after the zoom event. Here is the fix to my code:
% --------------------------------------------------------------------
function toolbar_zoomin_OnCallback(hObject, eventdata, handles)
% hObject handle to toolbar_zoomin (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global zoom_use current_object stop_updating;
zoom_use=0;
stop_updating = 0;
h = zoom(handles.del_pwr);
h = zoom(handles.gmag);
set(h,'ActionPostCallback',@mypostcallback);
set(h,'Enable','on');
current_object = gcf;
while zoom_use ==0
uiwait(gcf);
pushbutton_redrawsmithchart_Callback(hObject, eventdata, handles)
if stop_updating == 1
break;
end
end
% ----occurs after mouse button up for zoom function
function mypostcallback(obj,evd)
global newLim zoom_use current_object;
newLim = get(evd.Axes,'XLim');
disp(sprintf('The new X-Limits are [%.2f %.2f].',newLim));
zoom_use=1;
axis 'auto y';
disp(zoom_use);
uiresume(current_object);
% --------------------------------------------------------------------
function toolbar_zoomin_OffCallback(hObject, eventdata, handles)
% hObject handle to toolbar_zoomin (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global stop_updating;
zoom off;
stop_updating = 1;
In addition, in the last line of my redrawsmithchart function I have put the line:
zoom_use= 0;
to reset for the while loop.
There are probably more efficient ways of solving this but none that I can come up with. This also doesn't answer my original question of why I was receiving the error described above.

更多回答(1 个)

Angel Garcimartín
Angel Garcimartín 2013-10-16
For my part, I have discovered that you can the zoom and pan in two axes in a figure with linkaxes, which existence I ignored up to know. If you link several axes then zooming and panning in one will do the same in the others.
Your workaround is interesting, anyway.
I think that the problem with the mypostcallback function was that it does not receive the handles to pass to your redrawsmithchart function, so obviously it gives an error.

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by