Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在imrect MATLAB GUI上不停止_Matlab_User Interface_Callback - Fatal编程技术网

如何在imrect MATLAB GUI上不停止

如何在imrect MATLAB GUI上不停止,matlab,user-interface,callback,Matlab,User Interface,Callback,我想从显示的图像中获取矩形坐标。我想前后移动图像。这是我的MATLAB GUI: 所以当我按下下一步时,它应该会显示系列中的下一个图像,类似的是后退按钮。我正在使用以下代码: function next_Callback(hObject, eventdata, handles) % hObject handle to next (see GCBO) % eventdata reserved - to be defined in a future version of M

我想从显示的图像中获取矩形坐标。我想前后移动图像。这是我的MATLAB GUI:

所以当我按下下一步时,它应该会显示系列中的下一个图像,类似的是后退按钮。我正在使用以下代码:

function next_Callback(hObject, eventdata, handles)
    % hObject    handle to next (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)

    if handles.mypointer ~= length(handles.cur_images)
        handles.mypointer = handles.mypointer + 1;
        pic = imread(fullfile('images', handles.cur_images(handles.mypointer).name));
        handles.imageName=handles.cur_images(handles.mypointer).name;
        imshow(pic);
        h = imrect;
        getMyPos(getPosition(h));
        addNewPositionCallback(h, @(p) getMyPos(p));
        fcn = makeConstrainToRectFcn('imrect', get(gca, 'XLim'), get(gca, 'YLim'));
        setPositionConstraintFcn(h, fcn);
        handles.output = hObject;
        handles.posi = getPosition(h);
        guidata(hObject, handles);
但此代码的缺点是,当按下“下一步”按钮时,它会在
h=imrect
上停止,因此等待用户绘制矩形。如果我不画一个长方形,它什么也做不了。即使我再次按下“后退”或“下一步”按钮,它也不会执行任何操作,因为它仍在等待用户绘制矩形

如何不让程序停止?

一些注意事项:

  • 我认为最好的做法是将
    imrect
    移动到单独的按钮,如前面提到的Excaza
  • 我不能重复您的问题-我创建了一个GUI示例,所有按钮在执行
    imrect
    后都有响应
  • 我还建议执行
    h=imrect(handles.axes1)而不仅仅是'h=imrect;`(我不知道这是否与你的问题有关)
当我遇到MATLAB“阻塞函数”的问题时,我通过在计时器对象的回调函数中执行该函数来解决它。 我不知道这是否是一个好的做法;这只是我解决问题的方法。。。 在计时器回调中执行函数允许继续执行主程序流

下面的代码示例演示如何创建计时器对象,并在计时器的回调函数中执行
imrect
。 示例创建“SingleShot”计时器,并在执行time
start
函数200毫秒后触发要执行的回调

function timerFcn_Callback(mTimer, ~)
    handles = mTimer.UserData;
    h = imrect(handles.axes1); % Call imrect(handles.axes1) instead just imrect.
    % getMyPos(getPosition(h));
    % ...

    % Stop and delete the timer (this is not a good practice to delete the timer here - this is just an example).
    stop(mTimer);
    delete(mTimer);


function next_Callback(hObject, eventdata, handles)
    % if handles.mypointer~=length(handles.cur_images)
    % ...
    % h = imrect(handles.axes1);

    % Create new "Single Shot" timer (note: it is not a good practice to create new timer each time next_Callback is executed).
    t = timer;
    t.TimerFcn = @timerFcn_Callback; % Set timer callback function
    t.ExecutionMode = 'singleShot';  % Set mode to "singleShot" - execute TimerFcn only once.
    t.StartDelay = 0.2;              % Wait 200 msec from start(t) to executing timerFcn_Callback.
    t.UserData = handles;            % Set UserData to handles - passing handles structure to the timer.

    % Start timer (function timerFcn_Callback will be executed 200 msec after calling start(t)).
    start(t);

    disp('Continue execution...');

imrect
制作一个单独的按钮。。。