回调函数中的Getrect()存在运行时错误

时间:2014-04-26 20:44:46

标签: matlab matlab-figure

我正在使用滑块显示图像单元格数组中的新图像。基本上,如果滑块的值为“i”,则滑块的回调函数会在单元格数组中显示第i个图像。

在该回调函数中,我试图允许用户使用鼠标选择矩形。 MATLAB getrect()方法用于执行此操作 - 它在回调中无效:

Reference to a cleared variable GETRECT_H1.

Error in getrect (line 121)
elseif (~ishghandle(GETRECT_H1) || ...

Error in faceSliderGUI/slider_callback (line 23)
        rect = getrect(gca);

Error using waitfor
Error while evaluating uicontrol Callback

Reference to a cleared variable GETRECT_H1.

回调函数如下所示:

%# Callback function
    function slider_callback(hObj, eventdata)
        value = round(get(hObj,'Value')); 
        imageHandle = imshow(image_series{value});
        ah = get( imageHandle, 'Parent' );
        rect = getrect(ah); %let user draw a rectangle with mouse
        set(hTxt, 'String',num2str(value))       %# update text
    end

1 个答案:

答案 0 :(得分:2)

尝试使用imrect代替getrect

相关问题