ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
struct2hash.m
Go to the documentation of this file.
1%> \brief
2%> Return a ``hashmap`` cell array containing all field names
3%> and field values of input scalar MATLAB ``object`` as ``(key, val)``
4%> stored sequentially in the cell array.<br>
5%>
6%> \param[in] object : The input scalar MATLAB struct
7%> whose field names and values are
8%> to be converted to a ``hashmap`` cell.<br>
9%> \param[in] exkeys : The input vector of MATLAB strings
10%> containing a list of field names of the input ``object``
11%> that must be excluded from the output ``hashmap`` cell.<br>
12%> If the input argument ``unique`` is set to ``True``,
13%> then all elements of ``exkeys`` are compared to the
14%> object field and subfield names case-insensitively.<br>
15%> (**optional**, default = ``[]``)
16%> \param[in] unique : The input scalar MATLAB logical.<br>
17%> If ``true``, only the first instance of occurrence
18%> of any field name is added to the output cell array
19%> without considering case-sensitivity of the field names.<br>
20%> This argument also affects the input argument ``exkeys``.<br>
21%> (**optional**, default = ``false``)
22%> \param[in] onlyfull : The input scalar MATLAB logical.<br>
23%> If ``true``, only the field names with field values that
24%> are nonempty (as assessed by the MATLAB intrinsic ``isempty()``)
25%> are included in the output ``hashmap``.<br>
26%> (**optional**, default = ``false``)
27%>
28%> \return
29%> ``hashmap`` : The output cell array of even number of elements
30%> containing the field names and values of the input ``object``
31%> as ``(key, val)`` pairs stored sequentially as the cell elements.<br>
32%>
33%> \interface{struct2hash}
34%> \code{.m}
35%>
36%> hashmap = pm.matlab.hashmap.struct2hash(object)
37%> hashmap = pm.matlab.hashmap.struct2hash(object, exkeys)
38%> hashmap = pm.matlab.hashmap.struct2hash(object, [], unique)
39%> hashmap = pm.matlab.hashmap.struct2hash(object, exkeys, unique)
40%> hashmap = pm.matlab.hashmap.struct2hash(object, exkeys, [], onlyfull)
41%> hashmap = pm.matlab.hashmap.struct2hash(object, [], unique, onlyfull)
42%> hashmap = pm.matlab.hashmap.struct2hash(object, exkeys, unique, onlyfull)
43%> hashmap = pm.matlab.hashmap.struct2hash(object, [], [], onlyfull)
44%> hashmap = pm.matlab.hashmap.struct2hash(object, [], [], [])
45%>
46%> \endcode
47%>
48%> \example{struct2hash}
49%> \include{lineno} example/matlab/hashmap/struct2hash/main.m
50%> \output{struct2hash}
51%> \include{lineno} example/matlab/hashmap/struct2hash/main.out.m
52%>
53%> \final{struct2hash}
54%>
55%> \author
56%> \JoshuaOsborne, May 21 2024, 10:56 PM, University of Texas at Arlington<br>
57%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
58%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
59function hashmap = struct2hash(object, exkeys, unique, onlyfull)
60 fnameList = fieldnames(object);
61 fnameListLen = length(fnameList);
62 if nargin < 4; onlyfull = []; end
63 if nargin < 3; unique = []; end
64 if nargin < 2; exkeys = []; end
65 if isempty(unique); unique = false; end
66 if isempty(onlyfull); onlyfull = false; end
67 hashmap = cell(fnameListLen * 2, 1);
68 exkeys = string(exkeys);
69 if unique
70 fnameListLower = lower(fnameList);
71 exkeys = lower(exkeys);
72 end
73 counter = 0;
74 for i = 1 : fnameListLen
75 fname = string(fnameList{i});
76 if ~any(strcmp(exkeys, fname))
77 if ~(onlyfull && isempty(object.(fname))) && ~(unique && any(strcmpi(fnameListLower(1 : i - 1), fname)))
78 counter = counter + 1;
79 hashmap{counter} = fname;
80 counter = counter + 1;
81 hashmap{counter} = object.(fname);
82 end
83 end
84 end
85 hashmap = hashmap(1 : counter);
86end
function name(in vendor)
Return the MPI library name as used in naming the ParaMonte MATLAB shared library directories.
function list()
Return a list of MATLAB strings containing the names of OS platforms supported by the ParaMonte MATLA...
excluded
Definition: show.m:173
function struct2hash(in object, in exkeys, in unique, in onlyfull)
Return a hashmap cell array containing all field names and field values of input scalar MATLAB object...