我在 switch-case 语句中的 while 循环有问题,与回调函数和“drawnow”一起使用。在我的代码中,虽然 switch-case 的情况由 uicontrol 中的按钮确定,但 case 语句涉及进一步的回调函数,以使用“windowbuttondown/up/motionfcn”跟踪鼠标移动。但是,因为我在 case 语句的 while 循环内绘制了多个绘图,所以我使用了“drawnow”,这在我运行程序时给了我以下错误:
第 160 行错误 ==>drawow ??? 评估 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
结尾