“下一次审判” MATLAB 中的按钮

发布于 2025-01-01 00:58:34 字数 1490 浏览 2 评论 0原文

我有一个 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

它将目录中的两个随机图像拉到屏幕上,并带有滚动条和指令,用于确定滚动条上某个位置的两个图片之间的相关性/相似性级别。这一切都很好。

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不爱素颜 2025-01-08 00:58:34

像这样的东西怎么样:

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

clf 清除图形窗口: http://www.mathworks.de/help/techdoc/ref/clf.html
然后你的函数被简单地再次调用,然后将绘制到同一个窗口中!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文