matlab - 回调函数中的 Getrect() 有运行时错误

标签 matlab matlab-figure

我正在使用 slider 显示图像元胞数组中的新图像。基本上,如果 slider 的值为“i”,则 slider 的回调函数会显示元胞数组中的第 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

最佳答案

尝试使用 imrect 而不是 getrect

关于matlab - 回调函数中的 Getrect() 有运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23316331/

相关文章:

matlab - 在 Python 中使用 loadmat 加载 .mat 和 .m 文件

matlab - bsxfun 是否可用于稀疏矩阵

matlab - 从矩阵中删除特定元素

MATLAB 子图导出

matlab - 在同一个图表中绘制许多水平条形图

matlab - 在 matlab 中保存 imagesc 的精确图像输出

当打印为 .eps 时,Matlab 提供光栅化图形而不是矢量图形

Matlab 条形图分组但在不同的 y 尺度

matlab - 填充用 patch 函数绘制的矩形

c++ - 如何从 matlab 将图像值分配给 Triclops 结构