ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
struct2hash.m File Reference

Go to the source code of this file.

Functions

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 as (key, val) stored sequentially in the cell array.
More...
 

Function Documentation

◆ struct2hash()

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 as (key, val) stored sequentially in the cell array.

Parameters
[in]object: The input scalar MATLAB struct whose field names and values are to be converted to a hashmap cell.
[in]exkeys: The input vector of MATLAB strings containing a list of field names of the input object that must be excluded from the output hashmap cell.
(optional, default = [])
[in]unique: The input scalar MATLAB logical.
If true, only the first instance of occurrence of any field name is added to the output cell array without considering case-sensitivity of the field names.
(optional, default = false)
[in]onlyfull: The input scalar MATLAB logical. If true, only the structure field names field values are nonempty (as assessed by the MATLAB intrinsic isempty()) are included in the output hashmap.
(optional, default = false)
Returns
hashmap : The output cell array of even number of elements containing the field names and values of the input object as (key, val) pairs stored sequentially as the cell elements.


Possible calling interfaces

hashmap = pm.matlab.hashmap.struct2hash(object)
hashmap = pm.matlab.hashmap.struct2hash(object, exkeys)
hashmap = pm.matlab.hashmap.struct2hash(object, [], unique)
hashmap = pm.matlab.hashmap.struct2hash(object, exkeys, unique)
hashmap = pm.matlab.hashmap.struct2hash(object, exkeys, [], onlyfull)
hashmap = pm.matlab.hashmap.struct2hash(object, [], unique, onlyfull)
hashmap = pm.matlab.hashmap.struct2hash(object, exkeys, unique, onlyfull)
hashmap = pm.matlab.hashmap.struct2hash(object, [], [], onlyfull)
hashmap = pm.matlab.hashmap.struct2hash(object, [], [], [])


Example usage

1cd(fileparts(mfilename('fullpath'))); % Change working directory to source code directory.
2addpath('../../../../'); % Add the ParaMonte library root directory to the search path.
3
4pm.matlab.show()
5pm.matlab.show('s = struct("key1", 1, "key2", "val2", "Key2", "val2duplicate", "key3", false, "key4", []);')
6 s = struct("key1", 1, "key2", "val2", "Key2", "val2duplicate", "key3", false, "key4", []);
7
8pm.matlab.show()
9pm.matlab.show('hashmap = pm.matlab.hashmap.struct2hash(s);')
10 hashmap = pm.matlab.hashmap.struct2hash(s);
11pm.matlab.show('hashmap')
12pm.matlab.show( hashmap )
13
14pm.matlab.show()
15pm.matlab.show('hashmap = pm.matlab.hashmap.struct2hash(s, "key1");')
16 hashmap = pm.matlab.hashmap.struct2hash(s, "key1");
17pm.matlab.show('hashmap')
18pm.matlab.show( hashmap )
19
20pm.matlab.show()
21pm.matlab.show('hashmap = pm.matlab.hashmap.struct2hash(s, [], true);')
22 hashmap = pm.matlab.hashmap.struct2hash(s, [], true);
23pm.matlab.show('hashmap')
24pm.matlab.show( hashmap )
25
26pm.matlab.show()
27pm.matlab.show('hashmap = pm.matlab.hashmap.struct2hash(s, "key1", true);')
28 hashmap = pm.matlab.hashmap.struct2hash(s, "key1", true);
29pm.matlab.show('hashmap')
30pm.matlab.show( hashmap )
31
32pm.matlab.show()
33pm.matlab.show('hashmap = pm.matlab.hashmap.struct2hash(s, "key1", [], true);')
34 hashmap = pm.matlab.hashmap.struct2hash(s, "key1", [], true);
35pm.matlab.show('hashmap')
36pm.matlab.show( hashmap )
function root()
Return a scalar MATLAB string containing the root directory of the ParaMonte library package.

Example output
1
2s = struct("key1", 1, "key2", "val2", "Key2", "val2duplicate", "key3", false, "key4", []);
3
4hashmap = pm.matlab.hashmap.struct2hash(s);
5hashmap
6hashmap{1}
7key1
8hashmap{2}
9 1
10hashmap{3}
11key2
12hashmap{4}
13val2
14hashmap{5}
15Key2
16hashmap{6}
17val2duplicate
18hashmap{7}
19key3
20hashmap{8}
21 0
22hashmap{9}
23key4
24hashmap{10}
25
26hashmap = pm.matlab.hashmap.struct2hash(s, "key1");
27hashmap
28hashmap{1}
29key2
30hashmap{2}
31val2
32hashmap{3}
33Key2
34hashmap{4}
35val2duplicate
36hashmap{5}
37key3
38hashmap{6}
39 0
40hashmap{7}
41key4
42hashmap{8}
43
44hashmap = pm.matlab.hashmap.struct2hash(s, [], true);
45hashmap
46hashmap{1}
47key1
48hashmap{2}
49 1
50hashmap{3}
51key2
52hashmap{4}
53val2
54hashmap{5}
55key3
56hashmap{6}
57 0
58hashmap{7}
59key4
60hashmap{8}
61
62hashmap = pm.matlab.hashmap.struct2hash(s, "key1", true);
63hashmap
64hashmap{1}
65key2
66hashmap{2}
67val2
68hashmap{3}
69key3
70hashmap{4}
71 0
72hashmap{5}
73key4
74hashmap{6}
75
76hashmap = pm.matlab.hashmap.struct2hash(s, "key1", [], true);
77hashmap
78hashmap{1}
79key2
80hashmap{2}
81val2
82hashmap{3}
83Key2
84hashmap{4}
85val2duplicate
86hashmap{5}
87key3
88hashmap{6}
89 0


Final Remarks


If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.

  1. If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
  2. If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.

This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.

Author:
Joshua Alexander Osborne, May 21 2024, 10:56 PM, University of Texas at Arlington
Fatemeh Bagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.
Amir Shahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin