Home > data-access > find_subjects.m

find_subjects

PURPOSE ^

Find subjects that have all the required variables

SYNOPSIS ^

function [ subject_ids ] = find_subjects( variables, experiments )

DESCRIPTION ^

Find subjects that have all the required variables
   Sometimes you need to find a list of subjects that have the particular
   variables you're going to need for a calculation.  This function should
   accomplish the search for those subjects.

   find_subjects( VARIABLES ), where VARIABLES is a cell array of variable
   names, searches for subjects with all those variables.

   find_subjects( VARIABLES, EXPERIMENTS ) restricts the results to
   subjects that are in the given array of experiment numbers.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [ subject_ids ] = find_subjects( variables, experiments )
0002 %Find subjects that have all the required variables
0003 %   Sometimes you need to find a list of subjects that have the particular
0004 %   variables you're going to need for a calculation.  This function should
0005 %   accomplish the search for those subjects.
0006 %
0007 %   find_subjects( VARIABLES ), where VARIABLES is a cell array of variable
0008 %   names, searches for subjects with all those variables.
0009 %
0010 %   find_subjects( VARIABLES, EXPERIMENTS ) restricts the results to
0011 %   subjects that are in the given array of experiment numbers.
0012 
0013 if nargin == 2
0014     possible_subjects = list_subjects(experiments);
0015 else
0016     possible_subjects = list_subjects();
0017 end
0018 
0019 if ~iscell(variables)
0020     variables = {variables};
0021 end
0022 
0023 subject_ids = func_filter(@(sid) has_all_vars(variables, sid), possible_subjects);
0024 
0025 
0026 end
0027 
0028 function has_all = has_all_vars(variables, subject_id)
0029 % returns true if the subject has all of the requested variables available
0030 
0031 has_all = 1;
0032 for i = 1:length(variables)
0033     if ~ has_variable(subject_id, variables{i})
0034         has_all = 0;
0035         return
0036     end
0037 end
0038 
0039 end

Generated on Tue 23-May-2017 03:00:58 by m2html © 2005