使用 drawnow:在评估 uicontrol 回调时中断



我在开关案例语句中的 while 循环中遇到问题,与回调函数和"drawnow"一起使用。在我的代码中,虽然开关大小写的大小写是由 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

结束

查看帮助:drawnow它中断回调。你在回调中调用你的函数。也许你可以用pause(0.01)代替它.

虽然我强烈建议你摆脱循环并使用回调。

最新更新