我在switch-case语句中遇到一个while循环问题,与回调函数和“drawow”一起使用。在我的代码中,虽然switch-case的情况由uicontrol中的按钮确定,但case语句涉及进一步的回调函数,以使用'windowbuttondown / up / motionfcn来跟踪鼠标移动。因为我在case语句中在while循环中绘制了多个绘图,但是,我使用'drawnow',这在运行程序时给出了以下错误:
第160行错误==>的DrawNow ???在评估uicontrol回调时中断
case语句中的代码片段在我独立运行时没有出现错误,但在与其余代码集成时会以某种方式产生问题,我在下面附上。任何帮助都会非常感激。非常感谢!
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
端