-
Notifications
You must be signed in to change notification settings - Fork 4
/
UVRA.m
63 lines (55 loc) · 2 KB
/
UVRA.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
function [ Data ] = UVRA(subjectId)
% Task script for a monetary R&A task with relaxed test-taking conditions.
% ("U" stands for "unlimited", "V" for vertical layout of the choices.)
%
% Like all main tasks scripts, this function loads config, executes requisite
% blocks, and records data for the subject whose ID is passed as an argument.
addpath(genpath('./lib'));
addpath(genpath('./tasks/UVRA'));
% Add subfolders we'll be using to path
% NOTE: genpath gets the directory and all its subdirectories
%% Setup
config = UVRA_blockDefaults();
if ~exist('subjectId', 'var') % Practice
subjectId = NaN;
config = setupPracticeConfig(config);
end
% Find-or-create subject data file *in appropriate location*
fname = [num2str(subjectId) '.mat'];
folder = fullfile(config.task.taskPath, 'data');
fname = [folder filesep fname];
[ Data, subjectExisted ] = loadOrCreate(subjectId, fname);
% TODO: Prompt experimenter if this is correct
if subjectExisted
disp('Subject file exists, reusing...')
elseif ~isnan(subjectId)
disp('Subject has no file, creating...')
end
%% Generate trials/blocks - if they haven't been generated before
% NOTE: If the number of generated trials changes, config.task.numBlocks
% will need to be changed to an integer that divides the generated trial count.
if ~isfield(Data, 'blocks') || isempty(Data.blocks)
blocks = generateBlocks(config);
numBlocks = config.task.numBlocks;
Data.numFinishedBlocks = 0;
for blockIdx = 1:numBlocks
Data = addGeneratedBlock(Data, blocks{blockIdx}, config);
end
end
%% Display blocks
% Select which blocks to run
if ~isnan(subjectId)
[ firstBlockIdx, lastBlockIdx ] = getBlocksForSession(Data);
else
% Gut the generated blocks to be limited to practice
% TODO: Set this in config
practiceBlocks = 1;
numSelect = 8;
Data = preparePractice(Data, practiceBlocks, numSelect);
[ firstBlockIdx, lastBlockIdx ] = getBlocksForPractice(practiceBlocks);
end
for blockIdx = firstBlockIdx:lastBlockIdx
Data = runNthBlock(Data, blockIdx);
end
unloadPTB(config);
end