Home > data-utility > get_csv_data.m

get_csv_data

PURPOSE ^

out = get_csv_data(csv, columns, IDs)

SYNOPSIS ^

function out = get_csv_data(csv, columns, IDs)

DESCRIPTION ^

 out = get_csv_data(csv, columns, IDs)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function out = get_csv_data(csv, columns, IDs)
0002 % out = get_csv_data(csv, columns, IDs)
0003 root = fullfile(get_multidir_root, 'data_vis', 'correlation');
0004 if exist(fullfile(root, csv), 'file')
0005     csv = fullfile(root, csv);
0006 end 
0007 
0008 data = dlmread(csv, ',', 1, 0);
0009 
0010 if sum(ismember(data(:,1), list_subjects())) ~= length(data(:,1))
0011     sprintf('First column in %s is not subject list', csv);
0012     if exist('IDs', 'var') && ~isempty(IDs)
0013         error('IDs was specified, but first column in %s is not subject list', csv);
0014     end
0015 end
0016 
0017 if ~exist('IDs', 'var') || isempty(IDs)
0018     subs = cIDs('all');
0019 else
0020     subs = cIDs(IDs);
0021 end
0022 
0023 if ~exist('columns', 'var') || isempty(columns)
0024 %     if ~isempty(subs)
0025 %         columns = 2:size(data,2);
0026 %     else
0027 %         columns = 1:size(data,2);
0028 %     end
0029     columns = 1:size(data,2);
0030 elseif strcmp(columns, 'all')
0031     columns = 1:size(data,2);
0032 end
0033 
0034 out.sub_list = subs;
0035 if ~isempty(subs)
0036     [~,b,c] = intersect_order(data(:,1), subs);
0037     out.data = NaN(length(subs), length(columns));
0038     out.data(c,:) = data(b,columns);
0039     out.has_variable = c;
0040 else
0041     out.data = data(:,columns);
0042 end
0043 
0044 out.data_headers = get_csv_headers(csv);
0045 out = orderfields(out);
0046 
0047 end

Generated on Wed 24-May-2017 00:00:56 by m2html © 2005