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

Go to the source code of this file.

Functions

function copy (in from, in to, in fields)
 Copy the contents of the struct/object from to the struct/object to recursively and without destroying the existing components in to.
More...
 

Function Documentation

◆ copy()

function copy ( in  from,
in  to,
in  fields 
)

Copy the contents of the struct/object from to the struct/object to recursively and without destroying the existing components in to.

Parameters
[in]from: The input scalar MATLAB struct whose (select) components must be copy/merged with the components of the input struct to.
[in]to: The input scalar MATLAB struct to which the components of from struct must be copied.
(optional, default = struct())
[in]fields: The input vector of MATLAB strings each element of which is a field name in from whose value has to be copied to the struct to.
(optional, default = fieldnames(from) or properties(from))
Returns
tonew : The output MATLAB struct containing the merger of the two input MATLAB structs.
If a field name in fields is common between from and to, the field value of from will overwrite the corresponding field value of to in the output tonew.


Possible calling interfaces

tonew = pm.matlab.struct.copy(from)
tonew = pm.matlab.struct.copy(from, to)
tonew = pm.matlab.struct.copy(from, [], fields)
tonew = pm.matlab.struct.copy(from, to, fields)


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('from = struct("key1", 1, "key2", "val2", "Key2", "val2duplicate", "key3", false, "key4", []);')
6 from = struct("key1", 1, "key2", "val2", "Key2", "val2duplicate", "key3", false, "key4", []);
7pm.matlab.show('to = struct("key1", "val1", "Key2", "Val2");')
8 to = struct("key1", "val1", "Key2", "Val2");
9
10pm.matlab.show()
11pm.matlab.show('new = pm.matlab.struct.copy(from);')
12 new = pm.matlab.struct.copy(from);
13pm.matlab.show('new')
14pm.matlab.show( new )
15
16pm.matlab.show()
17pm.matlab.show('new = pm.matlab.struct.copy(from, [], "key3");')
18 new = pm.matlab.struct.copy(from, [], "key3");
19pm.matlab.show('new')
20pm.matlab.show( new )
21
22pm.matlab.show()
23pm.matlab.show('new = pm.matlab.struct.copy(from, to, "key3");')
24 new = pm.matlab.struct.copy(from, to, "key3");
25pm.matlab.show('new')
26pm.matlab.show( new )
27
28pm.matlab.show()
29pm.matlab.show('new = pm.matlab.struct.copy(from, to);')
30 new = pm.matlab.struct.copy(from, to);
31pm.matlab.show('new')
32pm.matlab.show( new )
function root()
Return a scalar MATLAB string containing the root directory of the ParaMonte library package.

Example output
1
2from = struct("key1", 1, "key2", "val2", "Key2", "val2duplicate", "key3", false, "key4", []);
3to = struct("key1", "val1", "Key2", "Val2");
4
5new = pm.matlab.struct.copy(from);
6new
7new.key1
8 1
9new.key2
10val2
11new.Key2
12val2duplicate
13new.key3
14 0
15new.key4
16
17new = pm.matlab.struct.copy(from, [], "key3");
18new
19new.key3
20 0
21
22new = pm.matlab.struct.copy(from, to, "key3");
23new
24new.key1
25val1
26new.Key2
27Val2
28new.key3
29 0
30
31new = pm.matlab.struct.copy(from, to);
32new
33new.key1
34 1
35new.Key2
36val2duplicate
37new.key2
38val2
39new.key3
40 0
41new.key4


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:59 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