Contents

%eventfilemakerEROS.m - Creates a matlab format for p-pod event file from a saved xcell
%spreadsheet from E-prime
%Dr. Kyle Mathewson - 2008 - EMM

%This takes the xcell files for each subject from in_path and creates the
%event file which it puts in each subjects folder in the folder out_path
% 1- Regular UnDetected
% 2- Regular Detected
% 3- All no response
% 4- Target Miss
% 5- Target Hit
% 6- Mask FA
% 7- Mask CR

clear all
close all

parameters

n_blocks = 16;
n_trials = 72;
montag = 'a';
experiment = 'emm'
s_rate = 36.0625
in_path = 'C:\DATA\emm\beh\';
out_path_main = 'C:\DATA\emm\evt\';    %the seperate folders for each subject will be added on for each subject below
% '543'
subnums = {'1031'};  % enter all the subject you want to make them for
experiment =

emm


s_rate =

   36.0625

loop for each subject

blocks = [01; 02]

%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
for x = 1:size(subnums,1)

    subnum = subnums{x,1};
    out_path = [out_path_main];
    if (exist(out_path) == 0)
        mkdir (out_path);
    end
    [data,textdata] = xlsread([in_path subnum 'alldata']);     %read in xcell file and take out relevant info into variables
    n_rows = (size(data,1)-1);

    block = data(41:n_rows,46);
    block_start_time = data(41:n_rows,19);
    trial_type = textdata(42:n_rows+1,74);
    accuracy = data(41:n_rows,77);
    reaction_time = data(41:n_rows,92);
    fix_onset = data(41:n_rows,100);


    for row_counter = 1:size(fix_onset,1)

        %---------Codes the timing of each event marker
            eventfile(row_counter,1) = (  (fix_onset(row_counter,1) - block_start_time(row_counter,1))  +436)   -2223;
%         eventfile(row_counter,4) = block(row_counter,1);

        %------Codes the regular events
        if strcmp(trial_type(row_counter,1),'NULL') == 0
            if strcmp(trial_type(row_counter,1),'Regular') == 1
                    if reaction_time(row_counter,1) == 0
                        eventfile(row_counter,2) = 3;
                    else
                        eventfile(row_counter,2) = accuracy(row_counter,1)+1;
                    end
            end
            if strcmp(trial_type(row_counter,1),'Target') == 1
                    if reaction_time(row_counter,1) == 0
                        eventfile(row_counter,2) = 6;
                    else
                        eventfile(row_counter,2) = accuracy(row_counter,1)+4;
                    end
            end
            if strcmp(trial_type(row_counter,1),'Mask') == 1
                    if reaction_time(row_counter,1) == 0
                        eventfile(row_counter,2) = 9;
                    else
                        eventfile(row_counter,2) = accuracy(row_counter,1)+7;
                    end
            end
        else
            eventfile(row_counter,2) = 99;         %flag the interblock rows
        end

    end
    for row_counter=1:(size(eventfile,1)-(n_blocks-1))           %remove the interblock rows
        if eventfile(row_counter,2) == 99
            eventfile(row_counter,:) = [];
        end
    end
    oldevent = eventfile;
    for row_counter=1:size(eventfile,1)-1
        eventfile(row_counter,2) = eventfile(row_counter+1,2);
    end
    eventfile(:,1) = round(eventfile(:,1)/s_rate);
    for block = 1:n_blocks
        event = eventfile(((block-1)*n_trials)+1:(block*n_trials),:);
        exten=sprintf('%03.0f',block);
%         dlmwrite([out_path experiment subnum montag '.' exten], current_block, 'delimiter','\t','precision',8, 'newline', 'pc');    %output
        save([out_path experiment subnum montag '.' exten],'event','-mat');
    end
end
Error using xlsread (line 129)
XLSREAD unable to open file 'C:\DATA\emm\beh\1031alldata'.
File 'C:\DATA\emm\beh\1031alldata' not found.

Error in eventfilemakerEROS (line 41)
    [data,textdata] = xlsread([in_path subnum 'alldata']);     %read in xcell file and take out relevant info into variables