Skip to content

Commit

Permalink
implemented new policy that variable in mrk.event and epo.event must …
Browse files Browse the repository at this point in the history
…index events with their *first* dimension.
  • Loading branch information
BenjaminBlankertz committed Feb 9, 2014
1 parent 033e0d0 commit 30e8b5b
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 33 deletions.
10 changes: 5 additions & 5 deletions fileio/file_readBVmarkers.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@
% Round time to micro seconds
% Mrk.time= round(Mrk.time*1000)/1000;

Mrk.desc= M_desc';
Mrk.event.type= M_type';
Mrk.event.length= M_length';
Mrk.event.chan= M_chan';
Mrk.event.clock= M_clock';
Mrk.desc= M_desc;
Mrk.event.type= M_type;
Mrk.event.length= M_length;
Mrk.event.chan= M_chan;
Mrk.event.clock= M_clock;

if strcmp(opt.MarkerFormat, 'numeric'),
[toe,idx]= bbciutil_markerMappingSposRneg(Mrk.desc);
Expand Down
18 changes: 9 additions & 9 deletions markers/mrk_matchStimWithResp.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
% ISTIM: Indices of stimulus events from MRK_STIM which were selected.
% IRESP: Indices of response events from MRK_RESP which were selected.

% [email protected]
props= {'MinLatency' 0 '!DOUBLE[1]';
'MaxLatency' inf '!DOUBLE[1]';
'AllowOvershoot' 0 '!DOUBLE[1]';
'MissingresponsePolicy' 'reject' '!CHAR(reject accept)';

props= {'MinLatency' 0 '!DOUBLE[1]';
'MaxLatency' inf '!DOUBLE[1]';
'AllowOvershoot' 0 '!DOUBLE[1]';
'MissingresponsePolicy' 'reject' '!CHAR(reject accept)';
'MultiresponsePolicy' 'reject' '!CHAR(reject first last)';
'RemoveVoidClasses' 0 '!BOOL';
'Sort' 1 '!BOOL'};
'Sort' 1 '!BOOL'};
props_selectEvents = mrk_selectEvents;
props_sortChron= mrk_sortChronologically;

Expand Down Expand Up @@ -94,10 +94,10 @@

mrk= mrk_selectEvents(mrk_stim, istim, opt_selectEvents);
if ~strcmp(opt.MissingresponsePolicy,'reject'),
mrk.event.missingresponse= isnan(iresp);
mrk.event.missingresponse= isnan(iresp(:));
iresp(mrk.event.missingresponse)= 1;
end
mrk.event.latency= mrk_resp.time(iresp) - mrk.time;
mrk.event.latency= mrk_resp.time(iresp)' - mrk.time';
iresp2= iresp;
if isfield(mrk.event, 'missingresponse') && ~isempty(mrk.event.missingresponse),
mrk.event.latency(mrk.event.missingresponse)= NaN;
Expand All @@ -106,7 +106,7 @@
end

if ~strcmpi(opt.MultiresponsePolicy, 'reject'),
mrk.event.multiresponse= multiple;
mrk.event.multiresponse= multiple(:);
end

if opt.Sort,
Expand Down
21 changes: 11 additions & 10 deletions markers/mrk_mergeMarkers.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,32 @@
end
end

if xor(isfield(mrk1,'desc'), isfield(mrk2,'desc')),
warning('field ''desc'' not found in all markers: lost');
elseif isfield(mrk1,'desc'),
mrk.desc= cat(2, mrk1.desc, mrk2.desc);
end
%if xor(isfield(mrk1,'desc'), isfield(mrk2,'desc')),
% warning('field ''desc'' not found in all markers: lost');
%elseif isfield(mrk1,'desc'),
% mrk.desc= cat(2, mrk1.desc, mrk2.desc);
%end

%% Merge subfields of mrk.event
if xor(isfield(mrk1,'event'), isfield(mrk2,'event')),
warning('field ''event'' not found in all markers: lost');
elseif isfield(mrk1,'event'),
fields1= fieldnames(mrk1.event);
fields2= fieldnames(mrk2.event);
lost_fields= setdiff(union(fields1, fields2,'legacy'), intersect(fields1, fields2,'legacy'),'legacy');
lost_fields= setdiff(union(fields1, fields2), intersect(fields1, fields2,'legacy'));
if ~isempty(lost_fields),
lost_list= str_vec2str(lost_fields);
warning('events fields {%s} not found in all markers: lost', lost_list{:});
end
mrk.event= struct;
for Fld= intersect(fields1, fields2,'legacy')',
for Fld= intersect(fields1, fields2)',
fld= Fld{1};
tmp1= getfield(mrk1.event, fld);
tmp2= getfield(mrk2.event, fld);
di= min(find(size(tmp1)>1)); %% first nonvoid dimension
if isempty(di), di=1; end
mrk.event= setfield(mrk.event, fld, cat(di, tmp1, tmp2));
% di= min(find(size(tmp1)>1)); %% first nonvoid dimension
% if isempty(di), di=1; end
% mrk.event= setfield(mrk.event, fld, cat(di, tmp1, tmp2));
mrk.event= setfield(mrk.event, fld, cat(1, tmp1, tmp2));
end
end

Expand Down
5 changes: 2 additions & 3 deletions markers/mrk_selectEvents.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@
for Fld= fieldnames(mrk.event)'
fld= Fld{1};
tmp= getfield(mrk.event, fld);
sz= size(tmp);
subidx= repmat({':'}, 1, length(sz));
subidx{end}= ev;
subidx= repmat({':'}, 1, ndims(tmp));
subidx{1}= ev;
mrk.event= setfield(mrk.event, fld, tmp(subidx{:}));
end
end
Expand Down
3 changes: 2 additions & 1 deletion processing/proc_selectEpochs.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
for Fld= fieldnames(epo.event)',
fld= Fld{1};
tmp= getfield(epo.event, fld);
subidx= cat(2, repmat({':'}, 1, ndims(tmp)-1), {idx});
subidx= repmat({':'}, 1, ndims(tmp));
subidx{1}= ev;
epo.event= setfield(epo.event, fld, tmp(subidx{:}));
end
end
26 changes: 21 additions & 5 deletions transitional/convert_markers.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,30 @@

mrk= rmfield(mrk_old, {'pos','toe','fs'});

mrk.time= mrk_old.pos/mrk_old.fs*1000;
mrk.event= struct;
if isfield(mrk, 'toe'),
mrk.event.desc= mrk_old.toe(:);
end

if isfield(mrk, 'indexedByEpochs'),
mrk= rmfield(mrk, mrk.indexedByEpochs);
mrk.event= struct;
nEvents= length(mrk.time);
for Fld= mrk.indexedByEpochs,
fld= Fld{1};
mrk.event= setfield(mrk.event, fld, mrk_old.(fld));
fieldvar= mrk_old.(fld);
sz= fieldvar;
eventdim= find(sz==nEvents);
if isempty(eventdim),
error('no event information found in field %s', fld);
end
if length(eventdim)>1,
error('cannot decide event dimension in field %s', fld);
end
if eventdim~=length(sz),
dimorder= [eventdim setdiff(1:length(sz), eventdim)];
fieldvar= permute(fieldvar, dimorder);
end
mrk.event= setfield(mrk.event, fld, fieldvar);
end
end

mrk.time= mrk_old.pos/mrk_old.fs*1000;
mrk.desc= mrk_old.toe;

0 comments on commit 30e8b5b

Please sign in to comment.