MATLAB: error using drawnow: Interrupt while evaluating uicontrol Callback
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Akzeptierte Antwort
Sean de Wolski
am 9 Mai 2012
The moral of the story is: Don't use a while loop for this!
When the mouse is pushed the windowbuttondownfcn callback is fired. Inside this, change the windowbuttonmotionfcn to be your set of statements to execute while the button is down. Then when the windowbuttonupfcn is fired (i.e. release the mouse) reset the windowbuttonmotionfcn and fire the statements that you want for when they let up.
The solutions here may interest you:
0 Kommentare
Weitere Antworten (2)
Jan
am 9 Mai 2012
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.
Siehe auch
Kategorien
Mehr zu Interactive Control and Callbacks 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!