Predicting Mortality of ICU Patients: The PhysioNet/Computing in Cardiology Challenge 2012 1.0.0

File: <base>/sources/alistairewj_at_gmail.com/entry2/pnPreprocessRemovalIndices.m (2,237 bytes)
function [idxOut, N] = pnPreprocessRemovalIndices(tmp, idx, val, equalityFcnStr)
%PNPREPROCESSDELETEDATA	Generates indices to be used to remove data
%	[idxOut] = pnPreprocessRemovalIndices(tmp, idx, val, equalityFcnStr)
%       calculates the indices of data which satisfies some condition
%       specified by equalityFcnStr and val. For example, if equalityFcnStr
%       is 'eq' and val is 0, then the function locates the indices of tmp
%       which contain data equal to 0. These indices are then translated
%       into indices in the original data cell, to be used for data
%       deletion at a later point in PNPREPROCESSDATA.
%
%   [idxOut,N] = pnPreprocessRemovalIndices(tmp, idx, val, equalityFcnStr)
%   also outputs the number of entries being deleted.
%
%	Inputs:
%		tmp     - Cell array with data only from a given field
%       idx     - Indices that were used to extract tmp from the original
%           data cell array
%       val     - A value used for comparison with tmp
%		equalityFcnStr - The function used to compare val to data in tmp
%
%	Outputs:
%		idxOut  - Indices of data cell array to be deleted 
%		N       - Number of entries to be deleted
%
%	Example:
%       data = pnLoadTextFilesCell([bpath 'set-a']);
%       [tmp,idx] = pnExtractField(data,'HR');
%       [idxRem,N] = pnPreprocessRemovalIndices(tmp, idx, 0, 'eq');
%       for m=2:4
%           data(:,m) = cellfun(@pnPreprocessDeleteData,...
%               data(:,m), idxRem, 'UniformOutput', false);
%       end
%       fprintf('Deleted %2.0f values which were 0.\n',N);
%      
%
%	See also PNPREPROCESSDATA

%	Copyright 2012 Alistair Johnson

%	$LastChangedBy: alistair $
%	$LastChangedDate: 2012-03-13 12:17:58 +0000 (Tue, 13 Mar 2012) $
%	$Revision: 225 $
%	Originally written on PCWIN64 by Alistair Johnson, 09-Mar-2012 17:47:37
%	Contact: alistairewj@gmail.com
fcnTmp = str2func(equalityFcnStr);
idxRem = cellfun(@(x) fcnTmp(x,val), tmp(:,4),'UniformOutput',false);
idxOut = cellfun(@pnSubfcnRemIdx, idx, idxRem, 'UniformOutput',false);
N = sum(cell2mat(cellfun(@(x) sum(x), idxOut, 'UniformOutput', false)));

end

function [idx] = pnSubfcnRemIdx(idx, idxRem)
idx(idx) = idxRem;
end