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
      nTrials  = length(block(iBlock).trial);   
Jesse Heckman's avatar
Jesse Heckman committed
31
      signal   = block(iBlock).signal;  
Jesse Heckman's avatar
Jesse Heckman committed
32

Jesse Heckman's avatar
Jesse Heckman committed
33
34
      updateBlock(h,iBlock,signal);
      pb_vSafety(signal);                             % Checks for safe vestibular parameters!! 
Jesse Heckman's avatar
Jesse Heckman committed
35
      
Jesse Heckman's avatar
Jesse Heckman committed
36
37
38
39
40
41
      bDat(iBlock).signal = pb_vRunVC(signal);
      
      % Plot signals
      h.signals; cla; hold on; col = pb_selectcolor(2,2); pause(.1);
      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
42
   
Jesse Heckman's avatar
Jesse Heckman committed
43
44
45
46
47
48
49
50
51
52
53
54
      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();
         pause(1);
      end
   end 
Jesse Heckman's avatar
Jesse Heckman committed
55
56
57
   %% CHECK OUT
   %  store data
   
Jesse Heckman's avatar
Jesse Heckman committed
58
59
60
61
62
63
64
   set(h.buttonClose, 'Enable', 'on');
   set(h.buttonRun, 'Enable', 'on');
   set(h.buttonLoad, 'Enable', 'on');
end

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

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

function updateDat(h, Dat)
    % Updates the visual feedback data

    
end


Jesse Heckman's avatar
Jesse Heckman committed
92
93
94
95
96
97
98
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % 
%                                                           %
%       Part of Programmeer Beer Toolbox (PBToolbox)        %
%       Written by: Jesse J. Heckman (2018)                 %
%                                                           %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %