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

これにより、2つのランダムな画像がディレクトリから画面に表示され、スクロールバーと、スクロールバー上の位置を持つ2つの画像間の関連性/類似性のレベルを判断するための指示が表示されます。それはすべてうまくいっています。

ただし、「次の試行」ボタンを押すと、画面がリセットされ、2つの新しいランダムな画像が表示され、スクロールバーが中央に戻るように設定する必要があります。どうすればよいですか?これをオンラインで行う方法についての説明が見つかりません。

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 ; その後、関数が再度呼び出されるだけで、同じウィンドウにプロットされます。

于 2012-02-01T15:21:59.473 に答える