Skip to content

Commit

Permalink
fix divide by zero if few/no ABP annot
Browse files Browse the repository at this point in the history
  • Loading branch information
alistairewj committed Nov 11, 2016
1 parent c80a54b commit 3417291
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions detect_sqi.m
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,14 @@
% we can then use idxMap to determine if a beat is in window w
[tmp,idxMap] = histc(abp{m},xi);
tmp = tmp(1:max(idxMap));

% if tmp has 0s, we set them to 1
% the ABP will consequently be 0 / 1 == 0
idxBad = tmp==0;
if any(idxBad)
tmp(idxBad) = 1;
end

tmp2 = accumarray(idxMap(idxMap~=0),sqi_bp{m}(idxMap~=0,1)) ./ tmp;
idxKeep = unique(idxMap);
idxKeep(idxKeep==0) = [];
Expand Down Expand Up @@ -328,6 +336,14 @@
xi = tabpsqi(d,:);
% idxMap finds which window each abp beat corresponds
[tmp,idxMap] = histc(abp{m},xi);

% if tmp has 0s, we set them to 1
% the ABP will consequently be 0 / 1 == 0
idxBad = tmp==0;
if any(idxBad)
tmp(idxBad) = 1;
end

% accumarray sums the ABP SQIs with the same idxMap
% dividing by tmp makes abpsqi{m} the mean SQI
sqi_abp{m}(d,1:max(idxMap)) = accumarray(idxMap(idxMap~=0),sqi_bp{m}(idxMap~=0,1)) ./ tmp(1:max(idxMap));
Expand Down

0 comments on commit 3417291

Please sign in to comment.