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

Go to the source code of this file.

Functions

function hash2comp (in hashmap, in object, in insensitive, in extensible, in recursive)
 Return a copy of the input object whose property (or field) values are overwritten with the corresponding (key, val) pairs in the input hashmap cell array. More...
 

Function Documentation

◆ hash2comp()

function hash2comp ( in  hashmap,
in  object,
in  insensitive,
in  extensible,
in  recursive 
)

Return a copy of the input object whose property (or field) values are overwritten with the corresponding (key, val) pairs in the input hashmap cell array.

This functionality is useful for converting the variadic arguments of functions to the corresponding property values of objects with the functions.

Parameters
[in]hashmap: The input 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.
All keys in the input hashmap must already exist as fields/properties of the input object.
[in]object: The input scalar MATLAB struct or object whose property/field values are to be overwritten with the corresponding values from the input hashmap cell.
[in]insensitive: The input scalar MATLAB logical. If false, then keys within the input hashmap will be matched against the input object properties(or fields) case-sensitively.
(optional, default = false)
[in]extensible: The input scalar MATLAB logical.
If true, then keys in the input hashmap that are missing in the input object properties(or fields) will be added to output objnew.
This functionality requires the input object to be either a MATLAB struct or an object whose ultimate superclass is the MATLAB handle class, which allows adding new properties via addprop() method.
(optional, default = false)
[in]recursive: The input scalar MATLAB logical.
If true, then key-val pairs in the input hashmap that match struct-cell or match object-cell pattern will be also converted recursively like the parent input object until all sub-components are obtained recursively.
(optional, default = false)
Returns
objnew : The output copy of the input object whose property/field values are overwritten with the corresponding values from the input hashmap cell.


Possible calling interfaces

objnew = pm.matlab.hashmap.hash2comp(hashmap, object)
objnew = pm.matlab.hashmap.hash2comp(hashmap, object, [])
objnew = pm.matlab.hashmap.hash2comp(hashmap, object, [], [])
objnew = pm.matlab.hashmap.hash2comp(hashmap, object, [], [], [])
objnew = pm.matlab.hashmap.hash2comp(hashmap, object, [], [], recursive)
objnew = pm.matlab.hashmap.hash2comp(hashmap, object, [], extensible, [])
objnew = pm.matlab.hashmap.hash2comp(hashmap, object, insensitive, [], [])
objnew = pm.matlab.hashmap.hash2comp(hashmap, object, [], extensible, recursive)
objnew = pm.matlab.hashmap.hash2comp(hashmap, object, insensitive, [], recursive)
objnew = pm.matlab.hashmap.hash2comp(hashmap, object, insensitive, extensible, recursive)


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('hashmap = {"key1", 2, "key2", "hash", "key3", true, "key4", 0};')
6 hashmap = {"key1", 2, "key2", "hash", "key3", true, "key4", 0};
7pm.matlab.show('object = struct("key1", 1, "key2", "val2", "Key2", "val2duplicate", "key3", false, "key4", []);')
8 object = struct("key1", 1, "key2", "val2", "Key2", "val2duplicate", "key3", false, "key4", []);
9
10pm.matlab.show()
11pm.matlab.show('objnew = pm.matlab.hashmap.hash2comp(hashmap, object);')
12 objnew = pm.matlab.hashmap.hash2comp(hashmap, object);
13pm.matlab.show('objnew')
14pm.matlab.show( objnew )
function root()
Return a scalar MATLAB string containing the root directory of the ParaMonte library package.

Example output
1
2hashmap = {"key1", 2, "key2", "hash", "key3", true, "key4", 0};
3object = struct("key1", 1, "key2", "val2", "Key2", "val2duplicate", "key3", false, "key4", []);
4
5objnew = pm.matlab.hashmap.hash2comp(hashmap, object);
6objnew
7objnew.key1
8 2
9objnew.key2
10hash
11objnew.Key2
12val2duplicate
13objnew.key3
14 1
15objnew.key4
16 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:47 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