MATLAB: error using drawnow: Interrupt while evaluating uicontrol Callback
Mostrar comentarios más antiguos
Hi, I have a problem with a while loop inside a switch-case statement, used together with callback functions and "drawnow". In my code, while the cases of the switch-case are determined by pushbuttons in uicontrol, the case statements involves further callback functions to track mouse movements using 'windowbuttondown/up/motionfcn's. Because I draw multiple plots inside the while loop in the case statement, however, I use 'drawnow', which gives me the following error when I run the programme:
Error on line 160 ==> drawnow ??? Interrupt while evaluating uicontrol Callback
The piece of code inside the case statement gives no error when I run independently but somehow creates problem when is integrated with the rest of the code, which I attach below. Any help would be so much appreciated. Many thanks!
function programme(selection)
if nargin == 0
selection=0
end
switch selection
case 0 %start GUI and uicontrols to set up the cases i.e %programme(1), programme(2) etc
uicontrol('style','pushbutton',...
'string','First', ...
'position',[50 700 50 20], ...
'callback','programme(1);');
uicontrol('style','pushbutton',...
'string','Second', ...
'position',[150 700 50 20], ...
'callback','programme(2);');
case 1
%mouse track:
set(gcf,'windowbuttondownfcn','mousedown=1;');
set(gcf,'windowbuttonupfcn','mouseup=1;');
set(gcf,'windowbuttonmotionfcn','mousemotion=1;');
%to terminate the while loop, set up stopit=1 on one of uicontrol buttons:
uicontrol('style','pushbutton',...
'string','First', ...
'position',[50 700 50 20], ...
'callback','stopit=1;');
stopit=0;
while (stopit==0)
if mousedown==1
statements
if mouseup ==1
statements (plots)
mouseup=0;
mousedown=0;
mousedown=0;
end
end
drawnow
end
case 2
statements
otherwise
statements
end
Respuesta aceptada
Más respuestas (2)
Jan
el 9 de Mayo de 2012
0 votos
Because I cannot reproduce the error, I cannot guess its reason. Could you please post a program, which is working?
But I see another problem: What do you expect the callback "stopit=1;" to do? It modifies the variable "stopit" in the base-workspace, such that you can check it in the command window. But this does not matter the variable "stopit" inside your function "programme". I suggest to read Matt's GUI examples to learn how to use callbacks: FEX: 41 GUI examples.
1 comentario
inci
el 9 de Mayo de 2012
inci
el 10 de Mayo de 2012
0 votos
Categorías
Más información sobre Migrate GUIDE Apps en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!