1

我有一个脚本这个 MATLAB 脚本:

function semjudge

clc;

name = input('Name: ','s');
snum = input('Subject #: ','s');

files = dir(fullfile('pictures','*.png'));
index = randperm(length(files));
picture1 = files(index(1)).name;
picture2 = files(index(2)).name;
image1 = fullfile('pictures',picture1);
image2 = fullfile('pictures',picture2);
subplot(1,2,1); imshow(image1); title(picture1);
subplot(1,2,2); imshow(image2); title(picture2);

uicontrol('Style', 'text',...
        'Position', [200 45 200 20],...
        'String','How related are these pictures?');
uicontrol('Style', 'text',...
        'Position', [50 45 100 20],...
        'String','Unrelated');
uicontrol('Style', 'text',...
        'Position', [450 45 100 20],...
        'String','Closely related');
uicontrol('Style','pushbutton','String','Next Trial',...
        'Position', [250 350 100 20],...
        'Callback','next');

h = uicontrol(gcf,...
   'Style','slider',...
   'Min' ,0,'Max',50, ...
   'Position',[100 20 400 20], ...
   'Value', 25,...
   'SliderStep',[0.02 0.1], ...
   'BackgroundColor',[0.8,0.8,0.8]);

set(gcf, 'WindowButtonMotionFcn', @cb);

lastVal = get(h, 'Value'); 

function cb(s,e)
    if get(h, 'Value') ~= lastVal 
    lastVal = get(h, 'Value'); 
    fprintf('Slider value: %f\n', lastVal); 
    end
end

end

这会从一个目录中将两个随机图像拉到屏幕上,并带有一个滚动条和说明,以确定两个图片之间的相关性/相似性级别以及滚动条上的位置。这一切都很好。

不过,我想要的是设置它,以便在按下“下一次试用”按钮时,屏幕将重置,并带有两张新的随机图片,并且滚动条回到中间。我该怎么做呢?我在网上找不到任何有关如何执行此操作的说明。

4

1 回答 1

2

像这样的东西怎么样:

uicontrol('Style','pushbutton','String','Next Trial','Position', [250 350 100 20],'Callback','clf; semjudge()');

clf清除图形窗口: http: //www.mathworks.de/help/techdoc/ref/clf.html;然后再次调用您的函数,然后将其绘制到 SAME 窗口中!

于 2012-02-01T15:21:59.473 回答