pb_vRunExp.m 3.17 KB
Newer Older
Jesse Heckman's avatar
Jesse Heckman committed
1
function pb_vRunExp(expinfo,h)
Jesse Heckman's avatar
Jesse Heckman committed
2
3
4
5
6
7
8
9
10
11
12
13
% PB_VRUNEXP(varargin)
%
% PB_VRUNEXP() forms the core body of experimental paradigms in the VC, and 
% will loop over the trials.
%
% See also ...

% PBToolbox (2018): JJH: j.heckman@donders.ru.nl

   %% INITIALIZE
   %  load & read experiment
   
Jesse Heckman's avatar
Jesse Heckman committed
14
15
16
   [block, cfg]  	= pb_vReadExp(expinfo.expfile);     % struct
   nblocks       	= cfg.Blocks;
   nTotTrials    	= cfg.Trials;
Jesse Heckman's avatar
Jesse Heckman committed
17
   
Jesse Heckman's avatar
Jesse Heckman committed
18
19
20
   cnt               = 0;
   bDat(nblocks)     = struct;                        % pre-allocate data for speed
   tDat(nTotTrials)  = struct;
Jesse Heckman's avatar
Jesse Heckman committed
21
   
Jesse Heckman's avatar
Jesse Heckman committed
22
   set(h.buttonClose,   'Enable', 'off')                % avoid closing GUI during executing run function     
23
24
25
26
   set(h.buttonRun,     'Enable', 'off')
   set(h.buttonLoad,    'Enable', 'off')
   
   h.signals; cla; 
Jesse Heckman's avatar
Jesse Heckman committed
27
   %% BODY
Jesse Heckman's avatar
Jesse Heckman committed
28
   %  Iterate experiment
Jesse Heckman's avatar
Jesse Heckman committed
29
   
30
31
   pause(2);
   
Jesse Heckman's avatar
Jesse Heckman committed
32
   for iBlock = 1:nblocks
Jesse Heckman's avatar
Jesse Heckman committed
33
      % Runs blocks of trials with a vestibular condition
Jesse Heckman's avatar
Jesse Heckman committed
34
35
36
37
38
      nTrials  = length(block(iBlock).trial);
      
      signal(1)   = block(iBlock).signal.ver;  
      signal(2)   = block(iBlock).signal.hor;     
      
Jesse Heckman's avatar
Jesse Heckman committed
39
40
      updateBlock(h,iBlock,signal);
      pb_vSafety(signal);                             % Checks for safe vestibular parameters!! 
Jesse Heckman's avatar
Jesse Heckman committed
41
      
Jesse Heckman's avatar
Jesse Heckman committed
42
43
44
      bDat(iBlock).signal = pb_vRunVC(signal);
      
      % Plot signals
45
46
47
48
      h.signals; cla; hold on; 
      h.signals.YLim = [-50 50];
      col = pb_selectcolor(2,2);
      
Jesse Heckman's avatar
Jesse Heckman committed
49
50
      plot(bDat(iBlock).signal.v.t,bDat(iBlock).signal.v.x,'Color',col(1,:)); 
      plot(bDat(iBlock).signal.h.t,bDat(iBlock).signal.h.x,'Color',col(2,:));
Jesse Heckman's avatar
Jesse Heckman committed
51
   
Jesse Heckman's avatar
Jesse Heckman committed
52
53
54
55
56
      for iTrial = 1:nTrials
         % Runs all trials within one block
         cnt = cnt+1; 
         updateTrial(h, iTrial, cnt, nTotTrials, tDat);
            
57
58
         pb_vClearTrial(cnt,iBlock,iTrial);
         pb_vRecordData(expinfo,cnt);
Jesse Heckman's avatar
Jesse Heckman committed
59
60
         %pb_vRunTrial(experiment(iTrial));
         %pb_vFeedbackGUI();
61
         pause(1);
Jesse Heckman's avatar
Jesse Heckman committed
62
      end
Jesse Heckman's avatar
Jesse Heckman committed
63
      pause(2)
Jesse Heckman's avatar
Jesse Heckman committed
64
   end 
Jesse Heckman's avatar
Jesse Heckman committed
65
66
67
   %% CHECK OUT
   %  store data
   
68
69
   disp([newline newline 'Experiment finished!'])
   
Jesse Heckman's avatar
Jesse Heckman committed
70
71
72
   set(h.buttonClose,   'Enable', 'on');
   set(h.buttonRun,     'Enable', 'on');
   set(h.buttonLoad,    'Enable', 'on');
Jesse Heckman's avatar
Jesse Heckman committed
73
74
75
76
end

function updateBlock(h, iBlock, signal)
   % Updates the block information to the GUI
Jesse Heckman's avatar
Jesse Heckman committed
77
   
Jesse Heckman's avatar
Jesse Heckman committed
78
79
   bn = pb_sentenceCase(num2str(iBlock,'%03d'));                           % count block
   set(h.Bn,'string',bn);
Jesse Heckman's avatar
Jesse Heckman committed
80
   
81
   vs = ['V = ' pb_sentenceCase(signal(1).type) ...                        % VC stim
Jesse Heckman's avatar
Jesse Heckman committed
82
      ', H = ' pb_sentenceCase(signal(2).type)];
Jesse Heckman's avatar
Jesse Heckman committed
83
84
85
   set(h.Vs,'string',vs);
end

Jesse Heckman's avatar
Jesse Heckman committed
86
function updateTrial(h, iTrial, cnt, nTotTrials, Dat)
Jesse Heckman's avatar
Jesse Heckman committed
87
88
   % Updates the trial information to the GUI
   
89
   h.figure1.Name = ['vPrime - ' num2str(cnt) '/' num2str(nTotTrials) ' Trials'];      % counting title
Jesse Heckman's avatar
Jesse Heckman committed
90
   
91
   tn = num2str(iTrial,'%03d');                                                        % blocktrial
Jesse Heckman's avatar
Jesse Heckman committed
92
93
94
95
96
   set(h.Tn,'string',tn)
   
end


Jesse Heckman's avatar
Jesse Heckman committed
97
98
99
100
101
102
103
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % 
%                                                           %
%       Part of Programmeer Beer Toolbox (PBToolbox)        %
%       Written by: Jesse J. Heckman (2018)                 %
%                                                           %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %