How can I use a timerobject called within a GUI Callback function to implement a timer dependent input request

My question is how I can build a timer object function that is called from a gui callback function to iteratively record responses to displayed images? The timer function is started from within the callback function of a pushbutton, "START" in the figure. The user however is limited to 0.750 seconds before the response is saved as no response and the next image is shown. My problem is that I want to create code that advances the display of images stored in a cell by either the user inputting a direction(using uiwait & uiresume) or the time running out before the next image displays. Both the ascii of the key pressed and the time (using tic & toc) when the key is pressed are stored. Part of my code is as follows:
callstr = 'set(gcbf,''Userdata'',double(get(gcbf,''Currentcharacter''))) ; uiresume ' ;
hfig3a_main= figure('Visible','on','Name', 'Task 3a MOCK GUI',... 'MenuBar','none','NumberTitle','off','Toolbar','none',... 'Color',[0.941,0.941,0.941],'Position',[730 500 1550 850],... 'KeyPressFcn',callstr,'UserData',-1,'Resize','on');
im_timer=timer('Name','ImageTimer','Period',0.750,'StartDelay',0,... 'BusyMode','queue','ExecutionMode','fixedSpacing'); set(im_timer,'TimerFcn',@image_display);
function [ch,tim,tim_2]=image_display(source, eventdata, handles) callstr = 'set(gcbf,''Userdata'',double(get(gcbf,''Currentcharacter''))) ; uiresume ' ;
set(hfig3a_main,'KeyPressFcn',callstr);
N=192;
ch = cell(24,N) ;
tim = zeros(24,N);
tim_2 = zeros(24,N);
subj_response_acc=zeros(24,7);
subj_response_time=zeros(48,6);
subj_response_acc_by_key=zeros(24,4); % # of correct by key
subJ_response_time_by_key=zeros(48,4);
init_count=6;
load_index=1;
current_ld=get(hCond_Num_txt,'String');
row_index=uint8(str2num(get(hRowCount_txt,'String')));
col_index=uint8(str2num(get(hColCount_txt,'String')));
Subj_Data=get(hImCtl_bg,'UserData');
Dir_matrix=Subj_Data.Im_Dir_nums;
Size_matrix=Subj_Data.Im_Size_nums;
image_seq=Subj_Data.Im_Dir_Data;
image_seq_cen=image_seq{row_index,:};
i=get(im_timer,'TasksExecuted')
size_num=Size_matrix(row_index,i);
switch (size_num)
case 1
axis_scale = 6; % 20/10 acity
case 2
axis_scale = 10; % 20/15 acity
case 3
axis_scale = 12; % 20/20 acuity
case 4
axis_scale = 14; % 20/25 acuity
case 5
axis_scale = 16; % 20/30 acuity
case 6
axis_scale = 20; % 20/35 acuity
case 7
axis_scale = 24; % 20/40 acuity
case 8
axis_scale = 28; % 20/50 acuity
end
% set(hmain_axis,'Visible','on');
set (hImCtl_bg,'SelectedObject',[]);
if ~(i>length(size_num))
imshow(image_seq_cen(:,:,i),'Parent',hmain_axis);
set (hImage_count,'String',i);
% start(im_timer);
t_image=tic;
uiwait(hfig3a_main);
ch{row_index,i} = get(hfig3a_main,'UserData');
if ~isempty(ch{row,index,i}) && toc(t_image)<=0.750
tim(row_index,i)=toc(tim_image);
tim_2(row_index,i)=toc(t00);
else
ch{row_index,i}=-1;
tim(row_index,i)=0.750;
tim_2(row_index,i)=toc(t00);
end
delete(hmain_axis);
hmain_axis = axes('Parent',hfig3a_main,'Units','pixels',...
'Color',[1 1 1],'Position',[585 275 375 375],'XColor'...
[.941 .941 .941],'YColor',[.941 .941 .941],'Visible','off');
end
When I run this code, the first image is displayed but the program hangs on the uiwait command and doesn't go further so it nver gets to the other images or to recording hte user response.

回答 (0 件)

カテゴリ

質問済み:

2013 年 7 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by