MATLAB Answers

"Next trial" button

1 view (last 30 days)
Ryan
Ryan on 31 Jan 2012
Hello,
I have an experiment, the code of which is as follows:
function exWindowButtonMotionFcn
clc; % clear command window
figure; % open figure
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 function randomly displays two pictures from a directory on the screen, along with a scroll bar, and prompts for the user to indicate on the scroll bar the degree of relatedness/similarity between the two pictures. It works fine.
However, what I want to do is create a function 'next', which will be triggered by pressing the 'Next Trial' button. When you press the button, I want the experiment to be "reset" ... that is, two NEW random pictures will be shown, and the scrollbar reset to the middle. So each trial is a standalone, and you cycle through them by pressing the 'next trial' button.
How do I do this? I have searched for about half an hour and cannot find ANY indication of how to do this on Mathworks.

  0 Comments

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!