如何在按钮上使用set(gca,...)功能?

时间:2014-04-09 17:04:11

标签: matlab matlab-guide

我是matlab的新手,所以我可以错过很多东西。我正在尝试使用按钮向上或向下推动图片。但我被卡住了。我希望当我按下按钮时它应该改变位置。 ri_call(...)函数增加行的意思是它应该在按钮"行增量"被按下了。

所以这是我的代码:

 function ri_Callback(hObject, eventdata, handles)
% hObject    handle to ri (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.r =  handles.r -1;
    I= imread('pout.tif');    %picture reading
    imshow(I);
    I(handles.h:handles.r,handles.wid:handles.col,:) = 0;
    I= set(gca,'Position',get(gca,'Position') + [handles.r handles.c 0 0]);   % ????? not working on button
    imshow(I);
    % Update handles structure
    guidata(hObject, handles);

end

1 个答案:

答案 0 :(得分:2)

不要从set获得输出。而不是

I = set(gca,...)

覆盖你的图像,只需

set(gca,...)

此外,您需要将单位设置为正确执行set。假设handles.rhandles.c有像素:

set(gca,'Units','Pixels')
set(gca,'Position',...)

如果您要移动蒙版,请在蒙版中引入x,y偏移:

I(yoffset+(handles.h:handles.r),xoffset+(handles.wid:handles.col),:) = 0;

但我会将handles.h解释为高度,将handles.wid解释为宽度,将handles.r解释为方框角落的起始y坐标,将handles.col作为起点框的x坐标。这种解释会产生命令:

I((1:handles.h)+handles.r+yoffset-1,(1:handles.wid)+handles.col+xoffset-1,:) = 0;