나는 당신이 볼 수 있듯이 임의의 그림을 디렉토리에서 꺼내 사용자가 비교하도록 요구하는이 프로그램을 가지고있다. 슬라이더로 값을 설정 한 후 사용자는 슬라이더와 임의의 그림 쌍을 재설정하는 "다음 평가판"버튼을 누릅니다. 특정 횟수의 반복 (버튼 누름) 후 프로그램이 자동으로 종료되도록 코드를 수정하려면 어떻게해야합니까? (가급적이면 "실험 종료 됨"메시지 사용)?X 반복 후 MATLAB 프로그램을 중지 하시겠습니까?
MATLAB 설명서에서이 작업을 수행하는 방법에 관한 내용을 찾을 수 없습니다. 변수를 설정해야합니까? 버튼을 누를 때마다 "1"이 변수 값에 추가되어 특정 숫자 (예 : "100")에 도달하면 종료됩니다. 그렇게하는 것이 가장 쉬운 방법입니까?
여기 스크립트입니다 : 여기를 참조
function trials
files = dir(fullfile('samples','*.png'));
nFiles = numel(files);
combos = nchoosek(1:nFiles, 2);
index = combos(randperm(size(combos, 1)), :);
picture1 = files(index(1)).name;
picture2 = files(index(2)).name;
image1 = fullfile('samples',picture1);
image2 = fullfile('samples',picture2);
subplot(1,2,1); imshow(image1);
subplot(1,2,2); imshow(image2);
uicontrol('Style', 'text',...
'Position', [200 375 200 20],...
'String','How related are these pictures?');
uicontrol('Style', 'text',...
'Position', [50 375 100 20],...
'String','Unrelated');
uicontrol('Style', 'text',...
'Position', [450 375 100 20],...
'String','Closely related');
uicontrol('Style','pushbutton','String','Next Trial',...
'Position', [250 45 100 20],...
'Callback','clf; trials()');
h = uicontrol(gcf,...
'Style','slider',...
'Min' ,0,'Max',50, ...
'Position',[100 350 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
당신이 다시 구현하려고를 (http://en.wikipedia.org/wiki/Hot_or_Not)? – yuk