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

function [ pac2 ] = pnPaC2(data)
%PNPAC2	Extract PaC2 from the data, measured as PaO2 / PaCO2
%	[ pac2 ] = pnPaC2(data) calculates the "PaC2" from the data by taking
%	the ratio of PaO2 and PaCO2 for each time point containing synchronous
%	measurements of the two. The output is of the same form as 
%   PNEXTRACTFIELD.
%	
%
%	Inputs:
%		data    - Cell array of data inputs in standard format:
%           Column 1 - Subject IDs
%           Column 2 - Time stamp vectors for each subject
%           Column 3 - Feature name vectors for each subject
%           Column 4 - Data value vectors for each subject
%       Empty cells indicate no available measurements (missing data).
%
%	Outputs:
%		pac2    - Cell array of only pac2 data in standard format:
%           Column 1 - Subject IDs
%           Column 2 - Time stamp vectors for each subject
%           Column 3 - Feature name vectors for each subject (only contains
%           'PaC2')
%           Column 4 - Data value vectors for each subject
%       Empty cells indicate no available measurements (missing data).
%
%	Example
%       %=== Load data in
%       load('data_processed_cell.mat');
%
%       %=== Calculate score
%       [ pac2 ] = pnPaC2(data);
%	
%	See also PNEXTRACTFIELD PNLOADTEXTFILESCELL PNIANDREW PNMAIN 

%	References:
%       Physionet Challenge 2012
%       http://physionet.org/challenge/2012/

%	Copyright 2012 Alistair Johnson

%	$LastChangedBy: alistair $
%	$LastChangedDate: 2012-04-24 22:39:24 +0100 (Tue, 24 Apr 2012) $
%	$Revision: 342 $
%	Originally written on GLNXA64 by Alistair Johnson, 24-Apr-2012 14:02:09
%	Contact: alistairewj@gmail.com

%=== PaC2 = PaO2 / PaCO2
pao2 = 'PaO2';
pao2 = pnExtractField(data,pao2);
paco2 = 'PaCO2';
paco2 = pnExtractField(data,paco2);

%=== For each record, extract PaO2 times and calculate PaCO2 at them
pac2 = cell(size(paco2));
pac2(:,1) = paco2(:,1); % subject ID

N = size(paco2,1);
for k=1:N
    if isempty(pao2{k,2})
        continue;
    else
        %=== Get times for pao2 and fio2
        t1 = pao2{k,2}; t2 = paco2{k,2};
        
        %=== Intersection
        [t_impute,ti,tj] = intersect(t1,t2);
        
        pac2{k,2} = t_impute;
        pac2{k,3} = repmat({'PaC2'},numel(t_impute),1);
        pac2{k,4} = pao2{k,4}(ti) ./ paco2{k,4}(tj);
    end
end

end