Home > database > id_map2struct.m

id_map2struct

PURPOSE ^

Creates a struct field/value pairs from the first/second column of the input.

SYNOPSIS ^

function s = id_map2struct(id_map)

DESCRIPTION ^

 Creates a struct field/value pairs from the first/second column of the input. 
 s = id_map2struct(id_map);

 Generates a structure in which the names of the fields are given by the
 identifiers in the first column of id_map and the values are given by the
 second column in id_map.  id_map is a cell array.

 Example:

 id_map = {'EVOKES_EMOTION_ID', 185.1; ...
      'STRENGTH_EXPER_EMOT_ID', 191.1; ...
      'EMOTION_TYPE_ID', 192.1};

 results in 

 s.EVOKES_EMOTION_ID
 s.STRENGTH_EXPER_EMOT_ID
 s.EMOTION_TYPE_ID

 where the values in the right column of id_map populate their respective
 fields in s.  There is also a field called all that has all of the IDs in a
 single vector

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function s = id_map2struct(id_map)
0002 % Creates a struct field/value pairs from the first/second column of the input.
0003 % s = id_map2struct(id_map);
0004 %
0005 % Generates a structure in which the names of the fields are given by the
0006 % identifiers in the first column of id_map and the values are given by the
0007 % second column in id_map.  id_map is a cell array.
0008 %
0009 % Example:
0010 %
0011 % id_map = {'EVOKES_EMOTION_ID', 185.1; ...
0012 %      'STRENGTH_EXPER_EMOT_ID', 191.1; ...
0013 %      'EMOTION_TYPE_ID', 192.1};
0014 %
0015 % results in
0016 %
0017 % s.EVOKES_EMOTION_ID
0018 % s.STRENGTH_EXPER_EMOT_ID
0019 % s.EMOTION_TYPE_ID
0020 %
0021 % where the values in the right column of id_map populate their respective
0022 % fields in s.  There is also a field called all that has all of the IDs in a
0023 % single vector
0024 
0025 % 07/31/06 Petr Janata
0026 
0027 nid = size(id_map,1);
0028 
0029 s.all = [id_map{:,2}];
0030 
0031 for iid = 1:nid
0032   id_str = id_map{iid,1};
0033   s.(id_str) = id_map{iid,2};
0034 end
0035 
0036 return

Generated on Wed 22-May-2019 04:00:51 by m2html © 2003