Purpose: reverse engineer the appropriate population size from the name of a state variable, population, monitor, etc. Assumes Npop of source if this is the state variable for a connection mechanism. Assumes Npop of target if this is an intrinsic mechanism. Note: this is a helper function called by
0001 function [pop_size,pop_name,target] = dsGetPopSizeFromName(model,name) 0002 % Purpose: reverse engineer the appropriate population size from the name 0003 % of a state variable, population, monitor, etc. 0004 % 0005 % Assumes Npop of source if this is the state variable for a connection mechanism. 0006 % Assumes Npop of target if this is an intrinsic mechanism. 0007 % 0008 % Note: this is a helper function called by 0009 0010 % model=dsGenerateModel('dv/dt=@current+10;{iNa,iK}'); 0011 % name='E_1_iNa_m; 0012 % name='E_1_E_2_iAMPA_s'; 0013 % 0014 % Author: Jason Sherfey, PhD <jssherfey@gmail.com> 0015 % Copyright (C) 2016 Jason Sherfey, Boston University, USA 0016 0017 spec=model.specification; 0018 pops={spec.populations.name}; 0019 0020 % sort pops to search longest name first 0021 l=cellfun(@length,pops); 0022 [~,I]=sort(l,'descend'); 0023 pops=pops(I); 0024 0025 % find the target population 0026 found=0; 0027 for i=1:length(pops) 0028 test=sprintf('%s_',pops{i}); 0029 if regexp(name,['^' test]) % is this the target pop? 0030 target=pops{i}; % target pop found 0031 found=1; 0032 break; 0033 elseif strcmp(name,test) % this is a population name 0034 target=pops{i}; % target pop found 0035 found=1; 0036 break; 0037 end 0038 end 0039 if ~found 0040 error('target population not found.'); 0041 end 0042 0043 % check for target_source_mechanism 0044 found=0; 0045 for i=1:length(pops) 0046 test=sprintf('%s_%s_',target,pops{i}); 0047 if regexp(name,['^' test]) 0048 source=pops{i}; 0049 found=1; 0050 break; 0051 end 0052 end 0053 0054 if found 0055 % assume Npop of source if this is the state variable for a connection mechanism 0056 pop_name=source; 0057 else 0058 % assume Npop of target if this is an intrinsic mechanism 0059 pop_name=target; 0060 end 0061 0062 pop_size=model.parameters.([pop_name '_Npop']);