Advertisement
Guest User

Untitled

a guest
Oct 14th, 2012
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 7.64 KB | None | 0 0
  1. function hand_rotation3
  2.     global imcell anscell num_of_rounds flag max_time plus_time file_name_prefix flag2 ii
  3.    
  4.     %% setting definitions
  5.     % the number of photos that are shown
  6.     num_of_rounds=20;
  7.     % the location of the hand images in the computer
  8.     working_dir_data='C:\Users\Alex\Dropbox\base line assessments\eTests\HandRotation\';
  9.     % maximum time of response before the image disapear
  10.     max_time=3;
  11.     % time of delay between images (the time '+' is shown on the screen)
  12.     plus_time=2;
  13.     % location to save the data on an excel file
  14.     file_name_prefix = 'D:\project_haifa\HAND_ROTATION';
  15.    
  16.     %% the functions
  17.     file_list=dir([working_dir_data,'*.jpg']);
  18.     imcell = cell(2,numel(file_list));
  19.     for jj=1:length(file_list)
  20.         file_name=[working_dir_data (file_list(jj).name)];
  21.         imcell{1,jj} = imread(file_name);
  22.         imcell{2,jj} = file_list.name;
  23.     end
  24.     anscell= cell(num_of_rounds,5);
  25. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  26.  
  27. fh=figure('NumberTitle','off',...
  28.        'Name','alex1','color','k',...
  29.        'Menubar','none',...
  30.        'Position',[100 100 1400 800],...
  31.        'KeyPressFcn',@youPress);
  32. a1=uicontrol('Style','text','BackgroundColor','k','ForegroundColor','w',...
  33.           'String','HAND ROTATION TASK-',...
  34.           'FontSize',22,...
  35.           'FontWeight','bold','HorizontalAlignment','center',...
  36.           'Units','normalized','Position',[.25 .8 .3 .1]);
  37. a2=uicontrol('Style','text','BackgroundColor','k','ForegroundColor','w',...
  38.           'String','enter your ID number in the box and press continue',...
  39.           'FontWeight','bold','FontSize',14,...
  40.           'Units','normalized','Position',[.1 .6 .2 .1]);
  41. a3=uicontrol('Style','pushbutton','BackgroundColor','r',...
  42.           'String','CONTINUE','FontSize',14,...
  43.           'FontWeight','bold','Enable','on',...
  44.           'Units','normalized','Position',[.4 .6 .1 .1],'Callback',@ID_enter_callback);
  45. a4=uicontrol('Style','edit','BackgroundColor','g',...
  46.           'String','',...
  47.           'FontWeight','bold','FontSize',14,...
  48.           'Units','normalized','Position',[.5 .6 .2 .1]);
  49. a5=uicontrol('Style','text','BackgroundColor','k','ForegroundColor','w',...
  50.           'String',{'In the following task, a "+" will be presented at the center of the screen,';'';'and then picture of a hand will appear.';'';'Your task is to decide whether the picture is of right hand or left hand.';'';'If the picture is of a right hand, press the "I" key.';'';'If the picture is of a left hand, press the "E" key.';'';'Try to classify the pictures as quickly and accurately as you can.';'';'Get ready for the task by placing your fingers on the "E" and "I" keys.';'';'When you are ready to begin, press the CONTINUE.'},...
  51.           'FontWeight','bold','FontSize',14,'Visible','off','HorizontalAlignment','left',...
  52.           'Units','normalized','Position',[.1 .3 .7 .6]);
  53. a6=uicontrol('Style','pushbutton','BackgroundColor','r',...
  54.           'String','CONTINUE','FontSize',14,...
  55.           'FontWeight','bold','Enable','on','Visible','off',...
  56.           'Units','normalized','Position',[.5 .1 .1 .1],'Callback',@PROCEED_callback);
  57. a7=uicontrol('Style','text','BackgroundColor','k','ForegroundColor','w',...
  58.           'String','+',...
  59.           'FontWeight','bold','FontSize',24,'Visible','off','HorizontalAlignment','center',...
  60.           'Units','normalized','Position',[.35 .25 .3 .4]);  
  61. a8=uicontrol('Style','text','BackgroundColor','k','ForegroundColor','w',...
  62.           'String','You finished the task',...
  63.           'FontWeight','bold','FontSize',24,'Visible','off','HorizontalAlignment','center',...
  64.           'Units','normalized','Position',[.4 .3 .3 .4]);
  65. a9=uicontrol('Style','pushbutton','BackgroundColor','r',...
  66.           'String','EXIT','FontSize',14,...
  67.           'FontWeight','bold','Enable','on','Visible','off',...
  68.           'Units','normalized','Position',[.5 .2 .1 .1],'Callback',@EXIT_callback);
  69. uicontrol(a4)  
  70.  
  71. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%      
  72.  
  73.     function ID_enter_callback(~,~)
  74.         a= str2double(get(a4,'string'));
  75.         for zz=1:num_of_rounds
  76.             anscell{zz,1}=a;
  77.         end
  78.         set(a4,'Visible','off');
  79.         set(a2,'Visible','off');
  80.         set(a3,'Visible','off');
  81.         set(a5,'Visible','on');
  82.         set(a6,'Visible','on');
  83.     end    
  84.  
  85. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%      
  86.     function PROCEED_callback(~,~)
  87.         import java.awt.Robot;
  88.         import java.awt.event.*;
  89.         mouse = Robot;
  90.         set(a1,'Visible','off');
  91.         set(a5,'Visible','off');
  92.         set(a6,'Visible','off');
  93.         set(a7,'Visible','on');
  94.         pause(0.2);
  95.         set(0, 'PointerLocation', [600 600]);
  96.         pause(0.2);
  97.         mouse.mousePress(InputEvent.BUTTON1_MASK);
  98.         mouse.mouseRelease(InputEvent.BUTTON1_MASK);
  99.         flag=0;
  100.         flag2=1;
  101.         ii=1;
  102.         while ii<num_of_rounds
  103.             if flag2
  104.                 pause(plus_time);
  105.                 b=unidrnd(size(imcell,2));
  106.                 anscell{ii,2}=imcell{2,b};
  107.                 set(a7,'Visible','off');
  108.                 axes('Position',[.35 .3 .3 .3]);
  109.                 image(imcell{1,b});
  110.                 START_TIMER;
  111.                 tic;
  112.             end
  113.         end
  114.         set(a7,'Visible','off');
  115.         set(a8,'Visible','on');
  116.         set(a9,'Visible','on');
  117.     end
  118. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%      
  119.     t = timer('StartDelay',max_time,'TasksToExecute',1,...
  120.     'StartFcn',@timer_started,'TimerFcn',@timer_run,'StopFcn',@timer_stoped);
  121. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
  122. function youPress(~,eventdata)
  123.     if eventdata.Key== 'i' && ~flag2
  124.         flag=1;
  125.         c = toc;
  126.         anscell{ii,2}=c;
  127.         anscell{ii,3}='i';
  128.         set(a7,'Visible','on');
  129.         stop(t)
  130.     elseif eventdata.Key== 'e' && ~flag2
  131.         flag=1;
  132.         c = toc;
  133.         anscell{ii,2}=c;
  134.         anscell{ii,3}='e';
  135.         set(a7,'Visible','on');
  136.         stop(t)
  137.     end
  138. end
  139. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  140. function timer_started(~,~)
  141.         flag2=0;
  142.     end
  143. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  144.  
  145.     function timer_run(~,~)
  146.         if ~flag
  147.             anscell{ii,2}=2;
  148.             anscell{ii,3}=' ';
  149.         end
  150.     end
  151. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  152.     function timer_stoped(~,~)
  153.         if ~flag
  154.             anscell{ii,2}=2;
  155.             anscell{ii,3}=' ';
  156.             set(a7,'Visible','on');
  157.         end
  158.         ii=ii+1;
  159.         flag2=1;
  160.     end
  161. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  162.     function EXIT_callback(~,~)
  163.         file_name = strcat(file_name_prefix, '.xls');
  164.         name={'Patient ID',  'pic name ', 'toc ','key press','result'};
  165.         xlswrite( file_name,name,num2str(anscell{1,1}),'a1');
  166.         % for i=1:5
  167.         %     for j=1:num_of_rounds
  168.                 xlswrite( file_name,anscell,num2str(anscell{1,1}),'a2');
  169.         %     end
  170.         % end
  171.         close(fh);
  172.         delete(fh);
  173.     end
  174. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  175.     function START_TIMER
  176.         start(t);
  177.     end
  178. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement