MATLAB Answers

How to filter first fixation times for participants

5 views (last 30 days)
Ruth Ronalter
Ruth Ronalter on 26 Jul 2021
Edited: Ruth Ronalter on 9 Aug 2021
Edit: separated subjects and participants before attempted for loop, and removed unnecessary and obsolete information
I'm trying to filtrate for the first fixations per participant per trial for eyelink data in Matlab. I have been able to separate pilot and subject trials as below
filename='RES_IAS (1).xlsx'; %Renamed file as filename
rawdata=readtable('filename') %readcell undefined, used readtable instead
idxPilot = startsWith(lower(rawdata.ID),'pilot'); %index for ID 'pilot'
idxSubj = startsWith(lower(rawdata.ID),'subj'); %index for ID 'subject'
subjects_only = rawdata(idxSubj,:); %extract data only for subjects
pilots_only = rawdata(idxPilot,:); %extract data only for pilot
I then used sort rows to separate data that had fixation times, and then sorted again for the trial index to see when the first fixation times were.
subjects_only_sort= sortrows(subjects_only,{'IA_FIRST_FIXATION_TIME','ID'},{'ascend','descend'})
first_fixations = (subjects_only_sort(4006:end,:)); %extract only data with a fixation time > 0
subject_sort = sortrows(first_fixations,{'TRIAL_INDEX'},{'ascend'}); %srearrange to trial ID
So to try and filter for the first fixations I created an empty array and a suggested for loop to run them through
fixations = {}
for k = 1:numel(subject_sort)
if subject_sort.IA_FIRST_FIXATION_TIME > 0
first = subject_sort.TRIAL_INDEX==1
if subject_sort.TRIAL_INDEX == first
fixations = {fixations + first}
But I retrieve a line of several 0s, and my end array is still empty. What am I doing wrong?

Answers (1)

Peter Perkins
Peter Perkins on 26 Jul 2021
Like SS, I tried to make sense of this code. And I found the same thing: in a recent version of MATLAB, these few lines would have done the job:
>> t = readtable("RES_IAS (1).xlsx");
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table.
The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
>> idx = (t.IA_FIRST_SACCADE_START_TIME > t.time);
>> scatter(t.IA_FIRST_SACCADE_START_TIME(idx),t.time(idx))
>> xlabel('time stimulus presented (ms)'), ylabel('time saccade seen(ms)'), title('Filtered Trials')
As for the loop at the end, SS took a shot, but the original code is so broken that it's hard to know what it is supposed to do. It's almost certain that it can be rewritten with no loop at all, but I don't understand what it's intended to do.
I also see at least three variables in that table that could usefully be converted to categorical, which may make you life down the road more convenient.
Peter Perkins
Peter Perkins on 6 Aug 2021
Yes, retime is a method for timetables. Won't work on a table.

Sign in to comment.




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!