【问题标题】:Matlab getrect function - How to skip the mouse inputMatlab getrect函数 - 如何跳过鼠标输入
【发布时间】:2015-03-30 13:25:47
【问题描述】:

在 Matlab GUI 中,我需要一个用户鼠标输入作为我必须在轴 1 上绘制的矩形。

为此,我有以下代码:

   axes(handles.axes1);
   filename = 'A';
   img = imread(filename);
   imshow(img);
   hold on;
   rect_cord = getrect(handles.axes1);
   rectangle('Curvature', [0 0],'Position', [rect_cord],'EdgeColor',[1 0 0]);

此代码运行良好(接受用户输入并绘制矩形)。但是,对于某些图像,我不想从鼠标获取用户输入(使用 getrect)。在这种情况下,如何跳过 getrect 函数并转到下一张图像?

我有一个按钮(“下一个”),我想在按下按钮时显示下一个图像,而不是接受用户输入。

谢谢,

【问题讨论】:

    标签: matlab matlab-figure matlab-guide


    【解决方案1】:

    我将尝试改写和修改一下:您想在单击轴或图像时绘制一个矩形。

    因此: 首先,我建议将 getrect 部分放入另一个函数中。此功能仅应在单击图像时触发。所谓的“ButtownDownFcn”似乎很适合这份工作。使用 GUIDE 时,您会发现它在弹出的属性检查器中双击轴。 然后把getrect-部分放到这个函数中:

    function axes1_ButtonDownFcn(hObject, eventdata, handles)
    % hObject    handle to axes1 (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    rect_cord = getrect(handles.axes1);
    rectangle('Curvature', [0 0],'Position', [rect_cord],'EdgeColor',[1 0 0]);
    

    现在我认为这就是必须要做的一切。但是用坐标轴内的图或图像对此进行测试证明我错了:o

    遗憾的是,必须将轴的子级重定向到此函数,因为默认情况下,它仅分配给轴的背景(=空白轴)。

    通过网络搜索,我在这里找到了以下解决方案: Matlab in Chemical Engineering: Interacting with your graph through mouse clicks

    它的工作原理是这样的: 绘制图像时,您必须添加行

    % and we also have to attach the function to the children, in this
    % case that is the line in the axes.
    set(get(gca,'Children'),'ButtonDownFcn', @mouseclick_callback)
    

    希望有帮助!

    【讨论】:

      猜你喜欢
      • 2013-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多