Question

I have a script this MATLAB script:

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

This pulls up two random images from a directory onto the screen, with a scroll bar and instructions to determine the level of relatedness/similarity between the two pictures with a position on the scroll bar. That's all well and good.

What I want, though, is to set it so that when the "Next Trial" button is pressed, the screen will reset, with two NEW random pictures, and the scroll bar back in the middle. How do I do this? I can't find any instructions on how to do this online.

Was it helpful?

Solution

What about something like this:

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

clf to clear the figure window: http://www.mathworks.de/help/techdoc/ref/clf.html; and afterwards your function is simply called again which will than plot into the SAME window!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top