Skip to content

Commit

Permalink
bugfixes bugfixesbugfixesbugfixesbugfixesbugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Treder committed Sep 6, 2012
1 parent a651674 commit d02ab00
Show file tree
Hide file tree
Showing 22 changed files with 294 additions and 122 deletions.
2 changes: 1 addition & 1 deletion processing/online_movingAverage.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

% bb, ida.first.fhg.de

nSamples= getIvalIndices(ms, dat.fs);
nSamples= procutil_getIvalIndices(ms, dat.fs);
sdat = size(dat.x,1);

if isempty(state)
Expand Down
28 changes: 14 additions & 14 deletions processing/proc_average.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,36 @@
% names of classes (strings in a cell array), or 'ALL' (default)
%
% For compatibility PROC_AVERAGE can be called in the old format with CLASSES
% as second argument (which is now set via opt.classes):
% as second argument (which is now set via opt.Classes):
% CLASSES - classes of which the average is to be calculated,
% names of classes (strings in a cell array), or 'ALL' (default)
%
%Returns:
% EPO - updated data structure with new field(s)
% .N - vector of epochs per class across which average was calculated
% .std - standard deviation, if requested (opt.std==1),
% .std - standard deviation, if requested (opt.Std==1),
% format as epo.x.

% Benjamin Blankertz


props= { 'policy' 'mean' 'CHAR(mean nanmean median)'
'classes' 'ALL' 'CHAR'
'std' 0 'BOOL' };
props= { 'Policy' 'mean' '!CHAR(mean nanmean median)'
'Classes' 'ALL' '!CHAR'
'Std' 0 '!BOOL' };

if nargin==0,
out = props; return
end

epo = misc_history(epo);
misc_checkType(epo, 'STRUCT(x clab y)');
if nargin==2
opt.classes = varargin{:};
opt.Classes = varargin{:};
else
opt= opt_proplistToStruct(varargin{:});
end
[opt, isdefault]= opt_setDefaults(opt, props);
opt_checkProplist(opt, props);
epo = misc_history(epo);

%% delegate a special case:
if isfield(epo, 'yUnit') && isequal(epo.yUnit, 'dB'),
Expand All @@ -54,7 +54,7 @@
end

%%
classes = opt.classes;
classes = opt.Classes;

if ~isfield(epo, 'y'),
warning('no classes label found: calculating average across all epochs');
Expand All @@ -63,7 +63,7 @@
epo.className= {'all'};
end

if isequal(opt.classes, 'ALL'),
if isequal(opt.Classes, 'ALL'),
classes= epo.className;
end
if ischar(classes), classes= {classes}; end
Expand All @@ -90,7 +90,7 @@

sz= size(epo.x);
out.x= zeros(prod(sz(1:end-1)), nClasses);
if opt.std,
if opt.Std,
out.std= zeros(prod(sz(1:end-1)), nClasses);
if exist('mrk_addIndexedField')==2,
%% The following line is only to be executed if the BBCI Toolbox
Expand All @@ -103,7 +103,7 @@
out.N= zeros(1, nClasses);
epo.x= reshape(epo.x, [prod(sz(1:end-1)) sz(end)]);
for ic= 1:nClasses,
switch(lower(opt.policy)), %% alt: feval(opt.policy, ...)
switch(lower(opt.Policy)), %% alt: feval(opt.Policy, ...)
case 'mean',
out.x(:,ic)= mean(epo.x(:,evInd{ic}), 2);
case 'nanmean',
Expand All @@ -113,8 +113,8 @@
otherwise,
error('unknown policy');
end
if opt.std,
if strcmpi(opt.policy,'nanmean'),
if opt.Std,
if strcmpi(opt.Policy,'nanmean'),
out.std(:,ic)= nanstd(epo.x(:,evInd{ic}), 0, 2);
else
out.std(:,ic)= std(epo.x(:,evInd{ic}), 0, 2);
Expand All @@ -124,6 +124,6 @@
end

out.x= reshape(out.x, [sz(1:end-1) nClasses]);
if opt.std,
if opt.Std,
out.std= reshape(out.std, [sz(1:end-1) nClasses]);
end
10 changes: 5 additions & 5 deletions processing/proc_baseline.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@
switch(lower(opt.pos)),
case 'beginning',
dat.refIval= dat.t(1) + [0 msec];
Ti= getIvalIndices(dat.refIval, dat);
Ti= procutil_getIvalIndices(dat.refIval, dat);
case 'end',
dat.refIval= dat.t(end) - [msec 0];
Ti= getIvalIndices(dat.refIval, dat);
Ti= procutil_getIvalIndices(dat.refIval, dat);
case 'beginning_exact', % 150 msec = 15 samples (not 16).
Ti= 1:round(msec/1000*dat.fs);
dat.refIval= [dat.t(Ti(1)) dat.t(Ti(end))];
Expand All @@ -96,14 +96,14 @@
switch(lower(opt.pos)),
case 'beginning_exact', % [-150 0] = 15 samples not 16 (at fs= 100 Hz)
len= round(diff(ival)/1000*dat.fs);
Ti= getIvalIndices(ival, dat);
Ti= procutil_getIvalIndices(ival, dat);
Ti= Ti(1:len);
case 'end_exact',
len= round(diff(ival)/1000*dat.fs);
Ti= getIvalIndices(ival, dat);
Ti= procutil_getIvalIndices(ival, dat);
Ti= Ti(end-len+1:end);
otherwise,
Ti= getIvalIndices(ival, dat);
Ti= procutil_getIvalIndices(ival, dat);
end
dat.refIval= dat.t(Ti([1 end]));
end
Expand Down
2 changes: 1 addition & 1 deletion processing/proc_selectEpochs.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
if isfield(epo, 'event'),
for Fld= fieldnames(epo.event),
fld= Fld{1};
tmp= getfield(epo, fld);
tmp= getfield(epo.event, fld);
subidx= cat(2, repmat({':'}, 1, ndims(tmp)-1), {idx});
epo.event= setfield(epo.event, fld, tmp(subidx{:}));
end
Expand Down
8 changes: 4 additions & 4 deletions processing/utils/select_time_intervals.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@

% delete scores where nothing should be selected
if ~isempty(opt.IvalMax),
idx_keep= getIvalIndices(opt.IvalMax, epo_r);
idx_keep= procutil_getIvalIndices(opt.IvalMax, epo_r);
idx_rm= setdiff(1:size(epo_r.x,1), idx_keep);
epo_r.x(idx_rm,:)= 0;
end
Expand All @@ -149,7 +149,7 @@
tmp_r= epo_r;
if length(this_constraint)>=4,
% TODO: use new option ivalMax!
idx_keep= getIvalIndices(this_constraint{4}, epo_r);
idx_keep= procutil_getIvalIndices(this_constraint{4}, epo_r);
idx_rm= setdiff(1:size(tmp_r.x,1), idx_keep);
tmp_r.x(idx_rm,:)= 0;
end
Expand All @@ -164,7 +164,7 @@
else
ival(ii,[1 2])= tmp_ival;
nfo(ii)= tmp_nfo;
idx_rm= getIvalIndices(tmp_ival, epo_r);
idx_rm= procutil_getIvalIndices(tmp_ival, epo_r);
epo_r.x(idx_rm,:)= 0;
end
end
Expand Down Expand Up @@ -239,7 +239,7 @@
if isempty(opt.IvalPickPeak),
pick_idx= 1:length(score);
else
pick_idx= getIvalIndices(opt.IvalPickPeak, epo_r);
pick_idx= procutil_getIvalIndices(opt.IvalPickPeak, epo_r);
end
[nfo.peak_val, t0]= max(nfo.score(pick_idx));
ti= pick_idx(t0);
Expand Down
2 changes: 1 addition & 1 deletion processing/utils/select_timeival.m
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
timescore= movingAverage(timescore, smooth_sa, 'centered');
timescore= mean(timescore(:,chansel),2);
tempscore= zeros(size(timescore));
idx= getIvalIndices(opt.startIval, erd);
idx= procutil_getIvalIndices(opt.startIval, erd);
tempscore(idx)= timescore(idx);
[topscore,mm]= max(tempscore);
dt= 100/1000*erd.fs;
Expand Down
20 changes: 12 additions & 8 deletions visualization/axis_redrawFrame.m
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
function H= axis_redrawFrame(ax, varargin)

opt= propertylist2struct(varargin{:});
[opt, isdefault]= ...
set_defaults(opt, ...
'VPos', 0, ...
'LineWidth', 0.5);
props = {'VPos', 0 '!DOUBLE';
'LineWidth' 1 '!DOUBLE'
};

if nargin==0,
ax= gca;
if nargin==0
H= props; return
end

opt= opt_proplistToStruct(varargin{:});
[opt, isdefault]= opt_setDefaults(opt, props);
opt_checkProplist(opt, props);

misc_checkTypeIfExists('ax','!GRAPHICS');

old_ax= gca;

for ii= 1:length(ax),
if isequal(get(ax(ii),'XColor'),[1 1 1]) & ...
if isequal(get(ax(ii),'XColor'),[1 1 1]) && ...
isequal(get(ax(ii),'YColor'),[1 1 1]),
continue;
end
Expand Down
68 changes: 68 additions & 0 deletions visualization/axis_title.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
function ht= axis_title(title_list, varargin)
%AXIS_TITLE - Add a title to the current axis
%
%Synopsis:
% H= axis_title(TITLE, <OPT>)
%
%Input:
% TITLE: CHAR|CELL string or cell array of strings
% OPT: struct or property/value list of optional properties:
% .vpos - vertical position
% .color - font color in RGB format. Maybe an [nTit 3] matrix of color
% codes
% .font* - font properties like fontWeight, fontSize, ...
% .horizontalAlignment, .verticalAlignment
%
%Output:
% H: handle to the text object(s)
%
%Note:
% The position of the text object is defined *within* the axis. So you should
% set XLimMode and YLimMode to 'manual' before calling AXIS_TITLE.

props = { 'VPos' 1.02 '!DOUBLE';
'Color' [0 0 0] '!CHAR|!DOUBLE[3]';
'HorizontalAlignment' 'center' '!CHAR(left center right)';
'VerticalAlignment' 'bottom' '!CHAR(bottom center baseline top)';
};

if nargin==0,
H= props; return
end

opt= opt_proplistToStruct(varargin{:});
[opt, isdefault]= opt_setDefaults(opt, props);
opt_checkProplist(opt, props);
misc_checkType(title_list,'CHAR|CELL{CHAR}');


if opt.VPos<=0 && isdefault.verticalAlignment,
opt.VerticalAlignment= 'top';
end

if ~iscell(title_list),
title_list= {title_list};
end
nTit= length(title_list);
if nTit>1 && size(opt.Color,1)==1,
opt.Color= repmat(opt.Color, [nTit 1]);
end

opt_fn= fieldnames(opt);
ifp= find(ismember(opt_fn, {'HorizontalAlignment','VerticalAlignment'}));
ifp= cat(1, ifp, strmatch('font', opt_fn));
font_opt= struct_copyFields(opt, opt_fn(ifp));
font_pl= opt_structToProplist(font_opt);

gap= 1/nTit;
xx= (gap/2):gap:1;
XLim= get(gca, 'XLim');
xx= XLim(1) + xx*diff(XLim);
YLim= get(gca, 'YLim');
yy= YLim(1) + opt.VPos*diff(YLim);

ht= text(xx, yy*ones(1,nTit), title_list);
set(ht, font_pl{:});
for tt= 1:nTit,
set(ht(tt), 'color',opt.Color(tt,:));
end
8 changes: 4 additions & 4 deletions visualization/grid_getSubplots.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

if length(chans)>0 && ischar(chans{1}) && ...
strcmp(chans{1},'plus'),
search_type= 'ERP*';
chans= chans(2:end);
search_type= '^ERP'; % starting with 'ERP'
chans= chans(2:end);
else
search_type= 'ERP';
search_type= '^ERP$'; % only the word 'ERP'
end

hc= get(gcf, 'children');
Expand All @@ -25,7 +25,7 @@
for ih= 1:length(hc),
ud= get(hc(ih), 'userData');
if isstruct(ud) && isfield(ud,'type') && ischar(ud.type) && ...
strpatterncmp(search_type, ud.type),
regexp(ud.type,search_type),
if isempty(chans) || ~isempty(util_chanind(chans, ud.chan)),
isERPplot(ih)= 1;
end
Expand Down
14 changes: 7 additions & 7 deletions visualization/grid_markInterval.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
% default 0.8

fig_Visible = strcmp(get(gcf,'Visible'),'on'); % If figure is already inVisible jvm_* functions should not be called
if fig_Visible
jvm= jvm_hideFig;
end
% if fig_Visible
% jvm= jvm_hideFig;
% end

if ~exist('chans','var'), chans=[]; end
if ~exist('markCol','var'), markCol= 0.85; end
Expand All @@ -28,7 +28,7 @@


old_ax= gca;
if isnumeric(chans) & ~isempty(chans),
if isnumeric(chans) && ~isempty(chans),
hsp= chans;
else
hsp= grid_getSubplots(chans);
Expand Down Expand Up @@ -57,6 +57,6 @@
legend;
end

if fig_Visible
jvm_restoreFig(jvm);
end
% if fig_Visible
% jvm_restoreFig(jvm);
% end
12 changes: 7 additions & 5 deletions visualization/grid_plot.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
'YLim', [], 'DOUBLE[2]';
'PlotStd', 0, 'BOOL'};

props_channel = plot_channel2D;
props_channel = plot_channel1D;
props_addScale = grid_addScale;

if nargin==0,
Expand Down Expand Up @@ -217,7 +217,7 @@
end

if max(sum(epo.y,2))>1,
epo= proc_average(epo, 'std',opt.PlotStd);
epo= proc_average(epo, 'Std',opt.PlotStd);
end

if isempty(opt.Axes),
Expand Down Expand Up @@ -336,10 +336,12 @@
else
H.ax(ia)= get_backAxes('position', get_axisGridPos(mnt, ic));
end
H.chan(ia)= setfield(plot_channel(epo, mnt.clab{ic}, opt_channel, opt_plot{:}, ...
cchan = plot_channel(epo, mnt.clab{ic}, opt_channel, opt_plot{:}, ...
'YLim', yLim(ch2group(ia),:), ...
'AxisTitle', axestitle{ia}, 'Title',0, ...
'SmallSetup',1), 'Clab', mnt.clab{ic});
'SmallSetup',1);
cchan.clab = mnt.clab{ic};
H.chan(ia) = cchan;
if ic==DisplayChannels(1),
opt_plot{2}= 0;
H.leg= H.chan(ia).leg;
Expand All @@ -357,7 +359,7 @@
leg_pos(3:4)= leg_pos_orig(3:4); %% use original size
set(H.leg, 'position', leg_pos);
ud= get(H.leg, 'userData');
ud= set_defaults(ud, 'type','ERP plus', 'chan','legend');
ud= opt_setDefaults(ud,{ 'type','ERP plus', 'chan','legend'});
set(H.leg, 'userData',ud);
if exist('verLessThan')~=2 || verLessThan('matlab','7'),
set(H.leg, 'Visible','off');
Expand Down
Loading

0 comments on commit d02ab00

Please sign in to comment.