Home > database > ensemble_attach_compqid_str.m

ensemble_attach_compqid_str

PURPOSE ^

Attaches a compqid_str variable to the Ensemble data struct if none

SYNOPSIS ^

function data_st = ensemble_attach_compqid_str(data_st,~)

DESCRIPTION ^

 Attaches a compqid_str variable to the Ensemble data struct if none
 exists.

 INPUT:
   data_st - must contain at least question_id and subquestion variables

 OUTPUT:
   Items in the compqid_str variable have the form
   s<question_id>_<subquestion>, e.g. s1032_01

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function data_st = ensemble_attach_compqid_str(data_st,~)
0002 % Attaches a compqid_str variable to the Ensemble data struct if none
0003 % exists.
0004 %
0005 % INPUT:
0006 %   data_st - must contain at least question_id and subquestion variables
0007 %
0008 % OUTPUT:
0009 %   Items in the compqid_str variable have the form
0010 %   s<question_id>_<subquestion>, e.g. s1032_01
0011 
0012 % 04Sep2014 Petr Janata
0013 
0014 if ~all(ismember({'question_id','subquestion'},data_st.vars))
0015   error('%s: Both question_id and subquestion variables required', mfilename)
0016 end
0017 
0018 cols = set_var_col_const(data_st.vars);
0019 
0020 % Create the initial string
0021 tmp = strcat('s', num2str(data_st.data{cols.question_id}),'_',num2str(data_st.data{cols.subquestion},'%02d'));
0022 
0023 % Place into a cell array of strings
0024 tmp = cellstr(tmp);
0025 
0026 % Remove whitespace
0027 tmp = regexprep(tmp,'\s','');
0028 
0029 data_st.vars{end+1} = 'compqid_str';
0030 data_st.data{end+1} = tmp;
0031 
0032 end

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