Home > database > reformat_matlab_call.m

reformat_matlab_call

PURPOSE ^

Substitutes context-specific parameter values for parameters specific in

SYNOPSIS ^

function newStr = reformat_matlab_call(origStr, swap)

DESCRIPTION ^

 Substitutes context-specific parameter values for parameters specific in
 condition_matlab and stimulus_matlab callbacks in an Ensemble experiment

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function newStr = reformat_matlab_call(origStr, swap)
0002 % Substitutes context-specific parameter values for parameters specific in
0003 % condition_matlab and stimulus_matlab callbacks in an Ensemble experiment
0004 
0005 % 26Jun2014 Petr Janata
0006 
0007 % Strip out function parameters
0008 tokens = regexp(origStr,'\''(\w+)\''','tokens');
0009 tokens = [tokens{:}];
0010 pv_pairs = reshape(tokens,2,length(tokens)/2)';
0011 
0012 % Deal with variable substitutions as we build up the matlab function
0013 % call
0014 param_str = '';
0015 for iparam = 1:size(pv_pairs,1)
0016   currParam = pv_pairs{iparam,1};
0017   switch currParam
0018     case {'params','return_type'}
0019       param_str = [param_str sprintf('''%s'',''%s''', currParam, pv_pairs{iparam,2})];
0020     case 'formid'
0021       param_str = [param_str sprintf('''%s'', %d', currParam, swap.form_id)];
0022     case 'subid'
0023       param_str = [param_str sprintf('''%s'', ''%s''', currParam, swap.subject_id)];
0024     case 'sessid'
0025       param_str = [param_str sprintf('''%s'', %d', currParam, swap.session_id)];
0026     case 'lastvisited'
0027       param_str = [param_str sprintf('''%s'', %d', currParam, swap.last_visited)];
0028   end % switch currParam
0029   
0030   % Add a comma if needed
0031   if iparam < size(pv_pairs,1)
0032     param_str = [param_str ', '];
0033   end
0034 end % for iparam
0035 
0036 % Now reconstruct the MATLAB call
0037 newStr = cell2str([regexp(origStr,'^\w+(','match') param_str ');']);
0038 
0039 return

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003