Home > data-access > list_variables.m

list_variables

PURPOSE ^

Lists all variables for an array of subjects or experiments.

SYNOPSIS ^

function [tnames, subsdata] = list_variables(IDs, substring, intersectFLAG, fullpathsFLAG, trimFLAG)

DESCRIPTION ^

 Lists all variables for an array of subjects or experiments.
 
 substring : a character string that will filter variables accordingly
 
         e.g. list_variables(43, 'cevent inhand') will only return variables with
         'cevent' and 'inhand' in the name.
 
 intersectFLAG : if 1, the intersection of variables across all given subjects.
           if 0, the union of variables across all given subjects.
 
 examples:
         list_variables([1401 1402], 'vision');
         list_variables([32 34 39], 'cevent joint');
         list_variables([3201 34], 'cont2');

 Author: sbf@umail.iu.edu

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [tnames, subsdata] = list_variables(IDs, substring, intersectFLAG, fullpathsFLAG, trimFLAG)
0002 % Lists all variables for an array of subjects or experiments.
0003 %
0004 % substring : a character string that will filter variables accordingly
0005 %
0006 %         e.g. list_variables(43, 'cevent inhand') will only return variables with
0007 %         'cevent' and 'inhand' in the name.
0008 %
0009 % intersectFLAG : if 1, the intersection of variables across all given subjects.
0010 %           if 0, the union of variables across all given subjects.
0011 %
0012 % examples:
0013 %         list_variables([1401 1402], 'vision');
0014 %         list_variables([32 34 39], 'cevent joint');
0015 %         list_variables([3201 34], 'cont2');
0016 %
0017 % Author: sbf@umail.iu.edu
0018 
0019 if ~exist('intersectFLAG', 'var') || isempty(intersectFLAG)
0020     intersectFLAG = 0;
0021 end
0022 
0023 if ~exist('fullpathsFLAG', 'var') || isempty(fullpathsFLAG)
0024     fullpathsFLAG = 0;
0025 end
0026 
0027 if ~exist('trimFLAG', 'var') || isempty(trimFLAG)
0028     trimFLAG = 1;
0029 end
0030 
0031 [subs, ~, paths] = cIDs(IDs);
0032 
0033 subsdata = struct();
0034 tnames = cell(size(paths,1), 1);
0035 for t = 1:size(paths,1)
0036     tmp = paths{t,1};
0037     path = sprintf('%s*mat', tmp);
0038     files = dir(path);
0039     filenames = {files.name}';
0040     celltmp = cell(numel(filenames),1);
0041     if fullpathsFLAG
0042         for c = 1:numel(celltmp)
0043             celltmp{c} = [tmp filenames{c}];
0044         end
0045         filenames = celltmp;
0046     end
0047     tnames{t,1} = filenames;
0048 end
0049 
0050 subdata = tnames;
0051 tnames = unique(vertcat(tnames{:}));
0052 
0053 if exist('substring', 'var') && ~isempty(substring)
0054     substringparts = strsplit(substring, ' ');
0055     search = cellfun(@(a) cellfun(@isempty, strfind(tnames, a)) == 0, substringparts, 'un', 0);
0056     search = horzcat(search{:});
0057     search = all(search, 2);
0058     tnames = tnames(search);
0059 end
0060 
0061 tnames(cellfun(@isempty, tnames)) = [];
0062 
0063 if intersectFLAG
0064     subdata = cellfun(@(a) intersect(tnames, a), subdata, 'un', 0);
0065 end
0066 
0067 subsdata.all = tnames;
0068 subsdata.data = subdata;
0069 subsdata.subs = subs;
0070 if trimFLAG
0071     tnames = cellfun(@(a) a(1:end-4), tnames, 'un', 0);
0072 end
0073 
0074 end

Generated on Tue 23-May-2017 20:00:55 by m2html © 2005