GetRunStimList: Difference between revisions
(Created page with "From time to time, we may lose track of which stimuli lists are associated with a particular .mat experimental data file following an experiment. "Did this participant vi...") |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
From time to time, we may lose track of which stimuli lists are associated with a particular .mat experimental data file following an experiment. "Did this participant view the List A or List B items?", you might ask. The following MATLAB function (found in the usual place) takes a set of data file names (.mat) and a set of stimuli files associated with an experiment run using the same PsychToolBox design conventions used for the LDT experiment. The function iterates through each matfile and determines which of the stimuli lists contain the same sequence of items as those recorded in the trial-by-trial data. The variable ''stimlists'' is returned as an N × 2 cell array of .mat/.txt pairs. | From time to time, we may lose track of which stimuli lists are associated with a particular .mat experimental data file following an experiment. "Did this participant view the List A or List B items?", you might ask. The following MATLAB function (found in the usual place) takes a set of data file names (.mat) and a set of stimuli files associated with an experiment run using the same PsychToolBox design conventions used for the LDT experiment. The function iterates through each matfile and determines which of the stimuli lists contain the same sequence of items as those recorded in the trial-by-trial data. The variable ''stimlists'' is returned as an N × 2 cell array of .mat/.txt pairs. | ||
If no parameters are given, the user is prompted to select the .mat files and/or .txt stimuli files of interest, which is probably the easiest way to go about doing things. | |||
function stimlists=getRunStimList(matfiles, lists) | function stimlists=getRunStimList(matfiles, lists) | ||
Line 32: | Line 34: | ||
[~,stimlists,~]=cellfun(@(x) fileparts(x), stimlists, 'UniformOutput', false); | [~,stimlists,~]=cellfun(@(x) fileparts(x), stimlists, 'UniformOutput', false); | ||
end | end | ||
[[Category: MATLAB functions]] |
Latest revision as of 15:34, 29 September 2016
From time to time, we may lose track of which stimuli lists are associated with a particular .mat experimental data file following an experiment. "Did this participant view the List A or List B items?", you might ask. The following MATLAB function (found in the usual place) takes a set of data file names (.mat) and a set of stimuli files associated with an experiment run using the same PsychToolBox design conventions used for the LDT experiment. The function iterates through each matfile and determines which of the stimuli lists contain the same sequence of items as those recorded in the trial-by-trial data. The variable stimlists is returned as an N × 2 cell array of .mat/.txt pairs.
If no parameters are given, the user is prompted to select the .mat files and/or .txt stimuli files of interest, which is probably the easiest way to go about doing things.
function stimlists=getRunStimList(matfiles, lists) if(~exist('matfiles', 'var') || isempty(matfiles)) [FileName,PathName,~] = uigetfile('*.mat', 'Select a .mat data file','MultiSelect', 'on'); matfiles=fullfile(PathName, FileName); end if(~exist('lists', 'var') || isempty(lists)) [FileName,PathName,~] = uigetfile('*.txt', 'Select stimuli files','MultiSelect', 'on'); lists=fullfile(PathName, FileName); end datafiles=cellfun(@(x) load(x), matfiles); %some code to load in the stims from the stimfiles using readtable() stimfiles=cellfun(@(x) readtable(x), lists, 'UniformOutput', false); stimlists=cell(length(matfiles),2); %stimlists will be a nFiles*2 cell array of strings of the format: [matfile | stimfile] for i=1:length(datafiles) d=datafiles(i); %open each data file %determine which stim list matches the stims appearing in the data file stims={d.expinfo.data.stim}'; %iterate through all lists stimlists{i,1}=matfiles{i}; %make note of which matfile we are working on for j=1:length(stimfiles) sf=stimfiles{j}; if(isequal(stims, table2cell(sf(:,3)))) stimlists{i,2}=lists{j}; end end end [~,stimlists,~]=cellfun(@(x) fileparts(x), stimlists, 'UniformOutput', false); end