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] field : The input vector of MATLAB strings each element
13%> of
which is a field or
property name in ``from``
14%> whose value has to be copied to the
struct ``to``.<br>
15%> (**optional**,
default = ``fieldnames(from)`` or ``properties(from)``)
16%> \param[in] exclude : The input vector of MATLAB strings each element
17%> of
which is a field or property
name in ``from``
18%> whose value has to be skipped and
excluded from the
copy to the
struct ``to``.<br>
19%> (**optional**,
default = ``[]``)
22%> ``tonew`` : The output MATLAB
struct containing the
23%> merger of the two input MATLAB structs.<br>
24%> If a field
name in ``field`` is common between
25%> ``from`` and ``to``, the field value of ``from`` will
26%> overwrite the corresponding field value of ``to``
27%> in the output ``tonew``.<br>
32%> tonew = pm.matlab.copy(from)
33%> tonew = pm.matlab.copy(from, to)
34%> tonew = pm.matlab.copy(from, [], field)
35%> tonew = pm.matlab.copy(from, [], field, [])
36%> tonew = pm.matlab.copy(from, to, field, [])
37%> tonew = pm.matlab.copy(from, to, field, exclude)
38%> tonew = pm.matlab.copy(from, to, [], exclude)
39%> tonew = pm.matlab.copy(from, [], [], exclude)
44%> If a
name appears in both ``field`` and ``exclude`` input arguments, then it is
excluded.<br>
47%> \include{lineno} example/matlab/
copy/main.m
49%> \include{lineno} example/matlab/
copy/main.out.m
54%> \JoshuaOsborne, May 21 2024, 10:59 PM, University of Texas at Arlington<br>
55%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
56%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
57function tonew =
copy(from, to, field, exclude)
61 elseif pm.array.len(exclude) == 0
64 exclude = [string(exclude)];
72 field = fieldnames(from);
75 field = properties(from);
96 for i = 1 : length(field)
99 %%%% Skip the ``field``
if it is
excluded.
102 if isempty(exclude) || ~any(strcmp(exclude, field(i)))
105 %%%% Check
if the ``field`` is itself a
struct or object.
109 subFieldList = fieldnames(from.(field{i}));
112 subFieldList = properties(from.(field{i}));
119 %%%% Create the
new copy component.
122 if isempty(subFieldList)
123 tonewComponent = from.(field{i});
126 tonewComponent = tonew.(field{i});
127 catch % the ``field`` of from does not exist in to.
128 tonewComponent =
struct();
130 tonewComponent = pm.matlab.copy(from.(field{i}), tonewComponent, subFieldList);
134 %%%% Copy the field values.
138 tonew.(field{i}) = tonewComponent;
140 tonew.addprop(field{i});
141 tonew.(field{i}) = tonewComponent;
function name(in vendor)
Return the MPI library name as used in naming the ParaMonte MATLAB shared library directories.
function copy(in from, in to, in field, in exclude)
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...