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

function [MEAN_DATA_24, MEAN_DATA_48, DESCRIPTORS]= read_data(set_name)

cur_dir=pwd;
fdel='/';
if(ispc)
    fdel='\';
end
data_dir=[cur_dir fdel set_name fdel];


cd(data_dir)
records=dir('*.txt');
cd(cur_dir)

I=length(records);
DATA=zeros(I,3) + NaN;
display(['Processing records ...'])

tm=[];
category=[];
val=[];

[ALL_CATEGORIES,time_series_names,descriptors]=get_param_names();
num_params=length(ALL_CATEGORIES);
num_ts_params=length(time_series_names);
num_descriptors=length(descriptors);


MEAN_DATA_24=zeros(I,num_ts_params) + NaN;
MEAN_DATA_48=zeros(I,num_ts_params) + NaN;

DESCRIPTORS=zeros(I,num_descriptors) + NaN;

header={'tm','category','val'};
for i=1:I
    record_id=records(i).name(1:end-4);
    fname=[data_dir record_id '.txt'];
    
    fid_in=fopen(fname,'r');
    C=textscan(fid_in,'%q %q %f','delimiter', ',','HeaderLines',1);
    fclose(fid_in);
    for n=1:length(header)
        eval([header{n} '=C{:,n};'])
    end

    % saves the parsed data
    
    [times,values,names]=extract_param_series(tm,category,val);
        

    [ts_times,ts_values,ts_names]=get_param_subset(time_series_names,times,values,names);

    [des_times,des_values,des_names]=get_param_subset(descriptors,times,values,names);
    
    % plots all param time series
    %plot_params(times,values,names);
    
    DESCRIPTORS(i,:)=cell2mat(des_values(:))';
    
    means24=calculate_mean(ts_times,ts_values,ts_names,time_series_names,[0 24*60]);
    means48=calculate_mean(ts_times,ts_values,ts_names,time_series_names,[24*60 48*60]);
    MEAN_DATA_24(i,:)=means24;
    MEAN_DATA_48(i,:)=means48;
    
  %  savefile = 'parsed_data.mat';
   % save(savefile, 'means24', 'means48','times','values','names')
    
   % [risk,survival]=physionet2012(tm,category,val);

 %  SAPS_SCORES(i)=saps_score(tm,category,val,1,[0 24]);
   
  % SAPS_SCORES_48(i)=saps_score(tm,category,val,1,[24 48]);
    % The outputs of the analysis are now available in the risk (event 2)
    % and survival (event 1) variables output by the function.
    


end