我有一个脚本这个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这将从目录中随机拉出两个图像到屏幕上,带有滚动条和指令,用于确定两个图片之间的相关性/相似性级别和滚动条上的一个位置。这一切都很好。
不过,我想要设置的是,当按下"Next Trial“按钮时,屏幕将重置,并显示两个新的随机图片,滚动条回到中间。我该怎么做呢?我在网上找不到任何关于如何做到这一点的说明。
发布于 2012-02-01 23:21:59
下面这样的内容如何:
uicontrol('Style','pushbutton','String','Next Trial','Position', [250 350 100 20],'Callback','clf; semjudge()');使用clf清除图形窗口:http://www.mathworks.de/help/techdoc/ref/clf.html;然后简单地再次调用您的函数,它将绘制到相同的窗口!
https://stackoverflow.com/questions/9098006
复制相似问题