Verifies that rows match across subordinate structs within a given struct. match = ensemble_verify_row_match(data_st,params) Makes sure that rows match across subordinate data structures in the top-level data structure (data_st) for all of the variables specified in the match_vars fields of the params structure. If no match_vars field is specified, all common variables are matched. This function is a mechanism to make sure that data are not mis-aligned across things like question IDs when the intention is to extract a matrix of data from individual children data structures within a parent data structure.
0001 function match = ensemble_verify_row_match(data_st,params) 0002 % Verifies that rows match across subordinate structs within a given struct. 0003 % match = ensemble_verify_row_match(data_st,params) 0004 % 0005 % Makes sure that rows match across subordinate data structures in the 0006 % top-level data structure (data_st) for all of the variables specified in the 0007 % match_vars fields of the params structure. If no match_vars field is 0008 % specified, all common variables are matched. 0009 % 0010 % This function is a mechanism to make sure that data are not mis-aligned 0011 % across things like question IDs when the intention is to extract a matrix of 0012 % data from individual children data structures within a parent data structure. 0013 0014 % 02/04/07 Petr Janata 0015 0016 match = true; % start out optimistic 0017 0018 num_ds = length(data_st.vars); 0019 0020 if nargin < 2 || ~isfield(params,'match_vars') || isempty(params.match_vars) 0021 match_vars = data_st.data{1}.vars; 0022 else 0023 match_vars = params.match_vars; 0024 end 0025 nmatch = length(match_vars); 0026 0027 % Find the common set of variables to match on 0028 0029 % Compare the data 0030 for ids = 1:num_ds 0031 child_cols = set_var_col_const(data_st.data{ids}.vars); 0032 0033 for im = 1:nmatch 0034 curr_var = match_vars{im}; 0035 0036 ep.extract_var = curr_var; 0037 mtx = ensemble_extract_matrix(data_st,ep); 0038 0039 if isempty(mtx) 0040 match = false; 0041 return 0042 end 0043 0044 if iscellstr(mtx) 0045 ncol = size(mtx,2); 0046 for icol = 2:ncol 0047 if ~all(strcmp(mtx(:,icol),mtx(:,1))) 0048 match = false; 0049 return 0050 end 0051 end 0052 else 0053 if any(any(diff(mtx,1,2),2)) 0054 match = false; 0055 return 0056 end 0057 end 0058 end 0059 end % for ids 0060 0061 return 0062