pb_vRunExp.m 2.99 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
23
24
   set(h.buttonClose,   'Enable', 'off')                % avoid closing GUI during executing run function     
   set(h.buttonRun,     'Enable', 'off');
   set(h.buttonLoad,    'Enable', 'off') 
Jesse Heckman's avatar
Jesse Heckman committed
25
   %% BODY
Jesse Heckman's avatar
Jesse Heckman committed
26
   %  Iterate experiment
Jesse Heckman's avatar
Jesse Heckman committed
27
   
Jesse Heckman's avatar
Jesse Heckman committed
28
   for iBlock = 1:nblocks
Jesse Heckman's avatar
Jesse Heckman committed
29
      % Runs blocks of trials with a vestibular condition
Jesse Heckman's avatar
Jesse Heckman committed
30
31
32
33
34
      nTrials  = length(block(iBlock).trial);
      
      signal(1)   = block(iBlock).signal.ver;  
      signal(2)   = block(iBlock).signal.hor;     
      
Jesse Heckman's avatar
Jesse Heckman committed
35
36
      updateBlock(h,iBlock,signal);
      pb_vSafety(signal);                             % Checks for safe vestibular parameters!! 
Jesse Heckman's avatar
Jesse Heckman committed
37
      
Jesse Heckman's avatar
Jesse Heckman committed
38
39
40
      bDat(iBlock).signal = pb_vRunVC(signal);
      
      % Plot signals
Jesse Heckman's avatar
Jesse Heckman committed
41
      h.signals; cla; hold on; col = pb_selectcolor(2,2);
Jesse Heckman's avatar
Jesse Heckman committed
42
43
      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
44
   
Jesse Heckman's avatar
Jesse Heckman committed
45
46
47
48
49
50
51
52
53
      for iTrial = 1:nTrials
         % Runs all trials within one block
         cnt = cnt+1; 
         updateTrial(h, iTrial, cnt, nTotTrials, tDat);
            
         %pb_vClearTrial();
         %pb_vRecordData();
         %pb_vRunTrial(experiment(iTrial));
         %pb_vFeedbackGUI();
Jesse Heckman's avatar
Jesse Heckman committed
54
         pause(.1);
Jesse Heckman's avatar
Jesse Heckman committed
55
      end
Jesse Heckman's avatar
Jesse Heckman committed
56
      pause(2)
Jesse Heckman's avatar
Jesse Heckman committed
57
   end 
Jesse Heckman's avatar
Jesse Heckman committed
58
59
60
   %% CHECK OUT
   %  store data
   
Jesse Heckman's avatar
Jesse Heckman committed
61
62
63
   set(h.buttonClose,   'Enable', 'on');
   set(h.buttonRun,     'Enable', 'on');
   set(h.buttonLoad,    'Enable', 'on');
Jesse Heckman's avatar
Jesse Heckman committed
64
65
66
67
end

function updateBlock(h, iBlock, signal)
   % Updates the block information to the GUI
Jesse Heckman's avatar
Jesse Heckman committed
68
   
Jesse Heckman's avatar
Jesse Heckman committed
69
70
   bn = pb_sentenceCase(num2str(iBlock,'%03d'));                           % count block
   set(h.Bn,'string',bn);
Jesse Heckman's avatar
Jesse Heckman committed
71
   
Jesse Heckman's avatar
Jesse Heckman committed
72
73
   vs = ['V = ' pb_sentenceCase(signal(1).type) ...                       % VC stim
      ', H = ' pb_sentenceCase(signal(2).type)];
Jesse Heckman's avatar
Jesse Heckman committed
74
75
76
   set(h.Vs,'string',vs);
end

Jesse Heckman's avatar
Jesse Heckman committed
77
function updateTrial(h, iTrial, cnt, nTotTrials, Dat)
Jesse Heckman's avatar
Jesse Heckman committed
78
79
   % Updates the trial information to the GUI
   
Jesse Heckman's avatar
Jesse Heckman committed
80
   h.figure1.Name = ['vPrime - ' num2str(cnt) '/' num2str(nTotTrials) ' Trials'];    % counting title
Jesse Heckman's avatar
Jesse Heckman committed
81
   
Jesse Heckman's avatar
Jesse Heckman committed
82
83
84
85
86
87
   tn = num2str(iTrial,'%03d');                                            % blocktrial
   set(h.Tn,'string',tn)
   
end


Jesse Heckman's avatar
Jesse Heckman committed
88
89
90
91
92
93
94
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % 
%                                                           %
%       Part of Programmeer Beer Toolbox (PBToolbox)        %
%       Written by: Jesse J. Heckman (2018)                 %
%                                                           %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %