How to filter first fixation times for participants

3 visualizzazioni (ultimi 30 giorni)
Edit: separated subjects and participants before attempted for loop, and removed unnecessary and obsolete information
Hello,
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}
end
end
end
But I retrieve a line of several 0s, and my end array is still empty. What am I doing wrong?

Risposte (1)

Peter Perkins
Peter Perkins il 26 Lug 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.
  4 Commenti
Ruth Ronalter
Ruth Ronalter il 3 Ago 2021
Modificato: Ruth Ronalter il 3 Ago 2021
Actually I do have data for the first fixation times, I'm trying the setup
retime(first_fix, 'regular', methods,'firstvalue', 'subjects')
but I get' Error using methods;Not enough input arguments.
If I don't use methods, I get "Undefined function 'retime' for input arguments of type 'table'"
Do I need to use timetable or table2timetable first?
Peter Perkins
Peter Perkins il 6 Ago 2021
Yes, retime is a method for timetables. Won't work on a table.

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti


Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by