2010-05-27 44 views

回答

3

在GUIDE中,可以在GUI中绘制坐标轴。然后,在回调函数中,可以将图像绘制到轴上。个人而言,我宁愿没有GUI内部的图像,因为它会让所有事情都变得更加困难,如果您想仔细观察图像,或者抓住它来粘贴到另一个应用程序中,该图作为GUI的一部分可能不方便。因此,我更喜欢将图像在单独的数字窗口中打开。

0

试试下面的代码:

function movingimage 
    %# Plotting a figure 
    fig1=figure('Name','Plotting an image',... 
     'Unit','normalized', 'Position',[.1 .1 .8 .8]); 
    uicontrol(fig1,'Style','text','Unit','Normalized',... 
     'Position',[.9 .85 .1 .07],'String','Press the button below to move the image location.'); 
    uicontrol(fig1,'Style','pushbutton','Unit','Normalized',... 
     'Position',[.9 .8 .05 .05],'String','Move','Callback',{@action_Callback}); 

    %# Say, you wish to plot an image of relative dimension (.3 x .3) to the figure. 
    xdim=.3; ydim=.3; 
    %# Image's movable range in x is (1 - xdim) 
    dx=1-xdim; 
    %# Image's Movable range in y is (1 - ydim) 
    dy=1-ydim; 
    %# considering the size of the image... 
    pos = [.5*dx .5*dy xdim ydim]; %# Initial location of the image is at the center of the figure. 
    ax1 = axes('position',pos); 
    img = load('mandrill'); 
    image(img.X) 
    colormap(img.map);axis off;axis equal; 

    function action_Callback(hObj,eventdata) 
     pos=[rand(1)*dx rand(1)*dy xdim ydim]; 
     set(ax1,'position',pos); 
    end 
end