Home > functions > internal > dsSelectVariables.m

dsSelectVariables

PURPOSE ^

SELECTVARIABLES - determine what variables to plot

SYNOPSIS ^

function [variables,pop_names] = dsSelectVariables(labels,var_strings, varargin)

DESCRIPTION ^

SELECTVARIABLES - determine what variables to plot

 Usage:
   variables=dsSelectVariables(labels,var_strings)

 Inputs:
   - labels: cell array of variable names
   - var_strings: string or cell array of strings specifying variables to plot

 Outputs:
   - all labels matching specifications in var_strings

 Examples:
   labels={'pop1_v','pop1_iNa_m','pop1_iNa_h','pop2_v','pop2_av','time'};
   var_strings=[];
   var_strings='v';
   var_strings='pop1';
   var_strings='*_v';
   var_strings='pop1_v';
   var_strings='pop1_*';
   var_strings='pop2_*';
 
 Author: Jason Sherfey, PhD <jssherfey@gmail.com>
 Copyright (C) 2016 Jason Sherfey, Boston University, USA

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [variables,pop_names] = dsSelectVariables(labels,var_strings, varargin)
0002 %SELECTVARIABLES - determine what variables to plot
0003 %
0004 % Usage:
0005 %   variables=dsSelectVariables(labels,var_strings)
0006 %
0007 % Inputs:
0008 %   - labels: cell array of variable names
0009 %   - var_strings: string or cell array of strings specifying variables to plot
0010 %
0011 % Outputs:
0012 %   - all labels matching specifications in var_strings
0013 %
0014 % Examples:
0015 %   labels={'pop1_v','pop1_iNa_m','pop1_iNa_h','pop2_v','pop2_av','time'};
0016 %   var_strings=[];
0017 %   var_strings='v';
0018 %   var_strings='pop1';
0019 %   var_strings='*_v';
0020 %   var_strings='pop1_v';
0021 %   var_strings='pop1_*';
0022 %   var_strings='pop2_*';
0023 %
0024 % Author: Jason Sherfey, PhD <jssherfey@gmail.com>
0025 % Copyright (C) 2016 Jason Sherfey, Boston University, USA
0026 
0027 %% auto_gen_test_data_flag argin
0028 options = dsCheckOptions(varargin,{'auto_gen_test_data_flag',0,{0,1}},false);
0029 if options.auto_gen_test_data_flag
0030   varargs = varargin;
0031   varargs{find(strcmp(varargs, 'auto_gen_test_data_flag'))+1} = 0;
0032   varargs(end+1:end+2) = {'unit_test_flag',1};
0033   argin = [{labels}, {var_strings}, varargs]; % specific to this function
0034 end
0035 
0036 if nargin<2
0037   var_strings=[];
0038 end
0039 
0040 if isempty(var_strings)
0041   % set default: all pops with state variable of first element of labels
0042   var=regexp(labels{1},'_.*$','match');
0043   % add wildcard
0044   if isempty(var)
0045     var_strings={'*'};
0046   else
0047     var_strings={['*' var{1}]};
0048   end
0049 elseif ~iscell(var_strings)
0050   var_strings={var_strings};
0051 end
0052 
0053 % loop over cell array of variable indicators
0054 variables={};
0055 for i=1:length(var_strings)
0056   varstr=var_strings{i};
0057   % convert state variable into reg string to get variable for all pops
0058   if ~any(varstr=='*') && any(~cellfun(@isempty,regexp(labels,['_' varstr '$'])))
0059     varstr=['*_' varstr];
0060   end
0061   % convert any population name into reg string to get all variables in pop
0062   if ~any(varstr=='*') && any(~cellfun(@isempty,regexp(labels,['^' varstr '_'])))
0063     varstr=[varstr '_*'];
0064   end
0065   % add period to get all matches
0066   varstr=strrep(varstr,'*','.*');
0067   % find all matches
0068   matches=regexp(labels,['^' varstr '$'],'match');
0069   variables=cat(2,variables,matches{:});
0070 end
0071 
0072 % if nargout>1
0073   pop_names={};
0074   for i=1:length(variables)
0075     name=regexp(variables{i},'^([a-zA-Z0-9]+)_','tokens','once');
0076     pop_names{end+1}=name{1};
0077   end
0078 % end
0079 
0080 %% auto_gen_test_data_flag argout
0081 if options.auto_gen_test_data_flag
0082   argout = {variables, pop_names}; % specific to this function
0083   
0084   dsUnitSaveAutoGenTestData(argin, argout);
0085 end
0086 
0087 end

Generated on Tue 12-Dec-2017 11:32:10 by m2html © 2005