Home > data-analysis > extraction > extract_relative_measures.m

extract_relative_measures

PURPOSE ^

SYNOPSIS ^

function extract_relative_measures(var_list, subexpID, filename, args)

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function extract_relative_measures(var_list, subexpID, filename, args)
0002 
0003 subs = cIDs(subexpID);
0004 if ~iscell(var_list)
0005     var_list = {var_list};
0006 end
0007 measure = cell(1000,1000);
0008 allsubs = zeros(size(measure,1),1);
0009 allsubs(1:numel(subs),1) = subs;
0010 h1 = 'subid,,';
0011 h2 = sprintf('base:%s,total_number,total_trial_time', args.cevent_name);
0012 
0013 absidx = 1;
0014 relidx = 1;
0015 propidx = 1;
0016 for v = 1:numel(var_list)
0017     data_type = get_data_type(var_list{v});
0018     h1 = cat(2, h1, ',', var_list{v});
0019     switch data_type
0020         case {'cevent', 'event', 'cstream'}
0021             for t = 1:numel(args.prop_threshold{propidx})
0022                 tt = args.prop_threshold{propidx}(t);
0023                 if ~isempty(tt)
0024                     h1 = cat(2, h1, ',');
0025                     h2 = cat(2, h2, sprintf(',PROP_%.2f', tt));
0026                 end
0027             end
0028             propidx = propidx + 1;
0029         case {'cont'}
0030             if isfield(args, 'abs_threshold')
0031                 for t = 1:numel(args.abs_threshold{absidx})
0032                     tt = args.abs_threshold{absidx}(t);
0033                     if ~isempty(tt)
0034                         h1 = cat(2, h1, ',');
0035                         h2 = cat(2, h2, sprintf(',ABS_%.2f', tt));
0036                     end
0037                 end
0038                 absidx = absidx + 1;
0039             end
0040             if isfield(args, 'rel_threshold')
0041                 for t = 1:numel(args.rel_threshold{relidx})
0042                     tt = args.rel_threshold{relidx}(t);
0043                     if ~isempty(tt)
0044                         h1 = cat(2, h1, ',');
0045                         h2 = cat(2, h2, sprintf(',REL_%.2f', tt));
0046                     end
0047                 end
0048                 relidx = relidx + 1;
0049             end
0050     end
0051     h1 = h1(1:end-1);
0052 end
0053 
0054 for s = 1:numel(subs)
0055     c = 1;
0056     absidx = 1;
0057     relidx = 1;
0058     propidx = 1;
0059     for v = 1:numel(var_list)
0060         data_type = get_data_type(var_list{v});
0061         if strcmp(data_type, 'event')
0062             newargs = args;
0063             newargs = rmfield(newargs, 'label_matrix');
0064             [~,e,st,~] = get_chunks(var_list{v}, subs(s), newargs);
0065         else
0066             [~,e,st,~] = get_chunks(var_list{v}, subs(s), args);
0067         end
0068         if v == 1
0069             if ~isempty(e)
0070                 measure{s,c} = size(e.individual_ranges,1);
0071             else
0072                 measure{s,c} = NaN;
0073             end
0074             c = c + 1;
0075             gt = get_trial_times(subs(s));
0076             measure{s,c} = sum(gt(:,2) - gt(:,1));
0077             c = c + 1;
0078         end
0079         switch data_type
0080             case {'cevent', 'event'}
0081                 for t = 1:numel(args.prop_threshold{propidx})
0082                     tt = args.prop_threshold{propidx}(t);
0083                     if ~isempty(tt)
0084                         if ~isempty(st{1})
0085                             pstats = st{1}.individual_prop;
0086                             if ~isempty(strfind(var_list{v}, 'motion'))
0087                                 measure{s,c} = sum(pstats < tt)/size(pstats,1);
0088                             else
0089                                 measure{s,c} = sum(pstats > tt)/size(pstats,1);
0090                             end
0091                         else
0092                             measure{s,c} = NaN;
0093                         end
0094                         c = c + 1;
0095                     end
0096                 end
0097                 propidx = propidx + 1;
0098             case {'cstream'}
0099                 for t = 1:numel(args.prop_threshold{propidx})
0100                     tt = args.prop_treshold{propidx}(t);
0101                     if ~isempty(tt)
0102                         if ~isempty(st{1})
0103                             pstats = st{1}.cevent_stats.individual_prop;
0104                             measure{s,c} = sum(pstats > tt)/size(pstats,1);
0105                         else
0106                             measure{s,c} = NaN;
0107                         end
0108                         c = c + 1;
0109                     end
0110                 end
0111                 propidx = propidx + 1;
0112             case {'cont'}
0113                 for t = 1:numel(args.abs_threshold{absidx})
0114                     tt = args.abs_threshold{absidx}(t);
0115                     if ~isempty(tt)
0116                         if ~isempty(st{1})
0117                             tstats = st{1}.individual_mean;
0118                             measure{s,c} = sum(tstats > tt)/size(tstats,1);
0119                         else
0120                             measure{s,c} = NaN;
0121                         end
0122                         c = c + 1;
0123                     end
0124                 end
0125                 absidx = absidx + 1;
0126                 for t = 1:numel(args.rel_threshold{relidx})
0127                     tt = args.rel_threshold{relidx}(t);
0128                     if ~isempty(tt)
0129                         if ~isempty(st{1})
0130                             rstats = st{2}.individual_mean;
0131                             measure{s,c} = sum(rstats > tt)/size(rstats,1);
0132                         else
0133                             measure{s,c} = NaN;
0134                         end
0135                         c = c + 1;
0136                     end
0137                 end
0138                 relidx = relidx + 1;
0139         end
0140     end
0141 end
0142 
0143 logmat = cellfun(@isempty, measure);
0144 measure(all(logmat, 2),:) = [];
0145 measure(:,all(logmat,1)) = [];
0146 allsubs = allsubs(all(logmat,2) == 0,1);
0147 
0148 datamatrix = cell2mat(measure);
0149 datamatrix = [allsubs datamatrix];
0150 log = all(isnan(datamatrix), 1);
0151 datamatrix(:,log) = [];
0152 hd = {h1, h2};
0153 for h = 1:2
0154     head = hd{h};
0155     head = strrep(head, ',', ' ,');
0156     head = strsplit(head, ',');
0157     head(log) = [];
0158     head = strjoin(head, ',');
0159     head(isspace(head)) = '';
0160     hd{h} = head;
0161 end
0162 
0163 write2csv(datamatrix, filename, hd);
0164 end

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