GetRunOrder

From CCN Wiki
Revision as of 15:54, 29 September 2016 by Chris (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

In the event that participants were run on several stimulus lists presented in a non-sequential order that has been since forgotten, the MATLAB function getRunOrder.m can recover the order in which a set of experimental data .mat files were created based on the timestamp field. This sequence it returned in the generated report value.

function report=getRunOrder(matfiles)
%Ensure that we know the names of the files to open
if(~exist('matfiles', 'var') || isempty(matfiles))
   [FileName,PathName,~] = uigetfile('*.mat', 'Select a .mat data file','MultiSelect', 'on');
   matfiles=fullfile(PathName, FileName);
end
datafiles=cellfun(@(x) load(x), matfiles);

timestamps=cell(1,length(datafiles));

%for each of the data files
for i=1:length(datafiles)
   d=datafiles(i); %open each data file
   timestamps{i}=d.expinfo.starttime; %extract the start timestamp

%determine which stim list matches the stims appearing in the data file
end
[sorted,tsidx]=sort(todatenum(cdfepoch(timestamps)));
%after sorting the timestamps, tsidx has the order in which the datafiles
%were generated. Can be used to report the filenames in sorted order:
%matfiles(tsidx)
report.matfiles=matfiles(tsidx)';
report.timestamps=timestamps';
end