2%> Copy the contents of the
struct/
object ``from``
3%> to the
struct/
object ``to`` recursively and without
4%> destroying the existing components in ``to``.<br>
6%> \param[in] from : The input scalar MATLAB
struct whose (select)
7%> components must be
copy/merged with the components
8%> of the input
struct ``to``.<br>
9%> \param[in] to : The input scalar MATLAB
struct to
which the
10%> components of ``from``
struct must be copied.<br>
11%> (**optional**,
default = ``
struct()``)
12%> \param[in] fields : The input vector of MATLAB strings each element
13%> of
which is a field
name in ``from`` whose value
14%> has to be copied to the
struct ``to``.<br>
15%> (**optional**,
default = ``fieldnames(from)`` or ``properties(from)``)
18%> ``tonew`` : The output MATLAB
struct containing the
19%> merger of the two input MATLAB structs.<br>
20%> If a field
name in ``fields`` is common between
21%> ``from`` and ``to``, the field value of ``from`` will
22%> overwrite the corresponding field value of ``to``
23%> in the output ``tonew``.<br>
28%> tonew = pm.matlab.struct.copy(from)
29%> tonew = pm.matlab.struct.copy(from, to)
30%> tonew = pm.matlab.struct.copy(from, [], fields)
31%> tonew = pm.matlab.struct.copy(from, to, fields)
36%> \include{lineno} example/matlab/
struct/
copy/main.m
38%> \include{lineno} example/matlab/
struct/
copy/main.out.m
43%> \JoshuaOsborne, May 21 2024, 10:59 PM, University of Texas at Arlington<br>
44%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
45%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
46function tonew =
copy(from, to, fields)
49 fields = fieldnames(from);
52 fields = properties(from);
71 for i = 1 : length(fields)
72 % check
if the ``field`` is itself a
struct or object.
74 subFieldList = fieldnames(from.(fields{i}));
77 subFieldList = properties(from.(fields{i}));
82 if isempty(subFieldList)
83 tonewComponent = from.(fields{i});
86 tonewComponent = tonew.(fields{i});
87 catch % the ``field`` of from does not exist in to.
88 tonewComponent =
struct();
90 tonewComponent = pm.matlab.struct.copy(from.(fields{i}), tonewComponent, subFieldList);
93 tonew.(fields{i}) = tonewComponent;
95 tonew.addprop(fields{i});
96 tonew.(fields{i}) = tonewComponent;
function name(in vendor)
Return the MPI library name as used in naming the ParaMonte MATLAB shared libraries.
function copy(in from, in to, in fields)
Copy the contents of the struct/object from to the struct/object to recursively and without destroyin...
function which(in vendor)
Return the a MATLAB string containing the path to the first mpiexec executable binary found in system...