Skip to content

Commit

Permalink
added reading of unit from header
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminBlankertz committed Feb 17, 2014
1 parent 357bb12 commit 5545a5a
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions fileio/file_readBVheader.m
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,38 @@
hdr.clab= cell(1, hdr.NumberOfChannels);
hdr.clab_ref= cell(1, hdr.NumberOfChannels);
hdr.scale= zeros(1, hdr.NumberOfChannels);
hdr.unitOfClab= cell(1, hdr.NumberOfChannels);
ci= 0;
while ci<hdr.NumberOfChannels,
str= fgets(fid);
if isempty(str) || str(1)==';', continue; end
[chno,chname,refname,resol]= ...
strread(str, 'Ch%u=%s%s%f%*[^\n]', 'delimiter',',');
[chno,chname,refname,resol,unit]= ...
strread(str, 'Ch%u=%s%s%f%s', 'delimiter',',');
ci= ci+1;
hdr.clab(ci)= chname(1);
hdr.clab_ref(ci)= refname(1);
hdr.unitOfClab{ci}= unit{1};
if resol==0,
resol= 1;
end
hdr.scale(ci)= resol;
end
units= unique(hdr.unitOfClab);
if length(units)==1,
% all channels hvae the same unit
if isempty(units{1}),
hdr.unit= 'a.u.';
else
hdr.unit= units{1};
end
else
% pick the prevalent unit
util_warning('different units found', 'readBVheader:units', 'Interval',10);
occurrences= cellfun(@(x)(length(strmatch(x,hdr.unitOfClab,'exact'))), ...
units);
[mm, midx]= max(occurrences);
unit= units{midx};
end

check= getEntry(fid, '[Coordinates]', 0, -1);
if check==1,
Expand Down

0 comments on commit 5545a5a

Please sign in to comment.