Syntax: dataStruct = loadFromTable( tableFile ) Inputs: tableFile: tab delimited file with column labels subject, trial, gazeX, gazeY, label Labels should be 0 or 1. label of 2 denotes unknown (exclude trial from analysis) Missing (x,y) coordinates denoted by -1 X,Y coordinates scaled in [0,1] range Outputs: dataStruct: structure containing the loaded data in a nice format including trackCell,allLabels, and sampsPerSubj
0001 % 0002 % Syntax: dataStruct = loadFromTable( tableFile ) 0003 % 0004 % Inputs: 0005 % tableFile: tab delimited file with column labels 0006 % subject, trial, gazeX, gazeY, label 0007 % Labels should be 0 or 1. 0008 % label of 2 denotes unknown (exclude trial from analysis) 0009 % Missing (x,y) coordinates denoted by -1 0010 % X,Y coordinates scaled in [0,1] range 0011 % 0012 % Outputs: 0013 % dataStruct: structure containing the loaded data in a nice format 0014 % including trackCell,allLabels, and sampsPerSubj 0015 0016 function dataStruct = loadFromTable( tableFile ) 0017 0018 % tableFile = 'exampleTable.txt'; 0019 0020 % load 0021 s = tdfread( tableFile ); 0022 trackCell = cell(1, max(s.subject)*max(s.trial)); 0023 allLabels = zeros( 1, max(s.subject)*max(s.trial)); 0024 0025 0026 subs = unique(s.subject); % list of subject numbers 0027 sampsPerSubj = zeros( length(subs),1); % for recording number trials 0028 0029 %loop through each subject 0030 fullIdx = 1; %for indexing data structure 0031 subjIdx = 1; 0032 for i1 = subs' 0033 % get data for this subject 0034 sIdx = find( s.subject == i1); 0035 trial = s.trial(sIdx); 0036 x = s.gazeX( sIdx ); 0037 y = s.gazeY( sIdx); 0038 lab = s.label( sIdx); 0039 0040 % split it up by trials 0041 trList = unique(trial); 0042 sampsPerSubj(subjIdx)= length(trList); % get number samples 0043 for i2 = trList' 0044 trIdx = find( trial == i2); 0045 % get gaze(x,i*y) and label 0046 trackCell{fullIdx} = x( trIdx)+ 1i*y(trIdx); 0047 allLabels( fullIdx) = lab(trIdx(1)); 0048 0049 % increment overallindex 0050 fullIdx = fullIdx+1; 0051 end 0052 % increment subject index 0053 subjIdx = subjIdx+1; 0054 end 0055 0056 % get data struct for output 0057 trackCell(fullIdx:end) = []; 0058 allLabels(fullIdx:end) = []; 0059 dataStruct.trackCell = trackCell; 0060 dataStruct.allLabels = allLabels; 0061 dataStruct.sampsPerSubj = sampsPerSubj; 0062 0063 0064