copy

Copy operating point or operating point specification

Syntax

op_point2 = copy(op_point1)
op_spec2 = copy(op_spec1)

Description

op_point2 = copy(op_point1) returns a copy of the operating point object op_point1. You can create op_point1 with the function operpoint.

op_spec2 = copy(op_spec1) returns a copy of the operating point specification object op_spec1. You can create op_spec1 with the function operspec.

Note

The command op_point2 = op_point1 does not create a copy of op_point1 but instead creates a pointer to op_point1. In this case, any changes made to op_point2 are also made to op_point1. The same is true for operating point specifications. For an example, see Copy an Operating-Point Specification.

Examples

collapse all

You can create new operspec variables in three ways:

  • Using the operspec command

  • Using assignment with the equals (=) operator

  • Using the copy command

Using the = operator results in linked variables that both point to the same underlying data. Using the copy command results in an independent operspec object. In this example, create operspec objects both ways, and examine their behavior.

mdl = 'watertank';
open_system(mdl);
opspec1 = operspec(mdl)
 Operating point specification for the Model watertank.
 (Time-Varying Components Evaluated at time t=0)

States: 
----------
(1.) watertank/PID Controller/Integrator/Continuous/Integrator
	 spec:  dx = 0,  initial guess: 0
(2.) watertank/Water-Tank System/H
	 spec:  dx = 0,  initial guess: 1

Inputs: None 
----------

Outputs: None 
----------

Create a new operating point specification object using assignment with the = operator.

opspec2 = opspec1;

opspec2 is an operspec object that points to the same underlying data as opspec1. Because of this link, you cannot independently change properties of the two operspec objects. To see this, change a property of opspec2. For instance, change the initial value for the first state from 0 to 2. The change shows in the States section of the display.

opspec2.States(1).x = 2
 Operating point specification for the Model watertank.
 (Time-Varying Components Evaluated at time t=0)

States: 
----------
(1.) watertank/PID Controller/Integrator/Continuous/Integrator
	 spec:  dx = 0,  initial guess: 2
(2.) watertank/Water-Tank System/H
	 spec:  dx = 0,  initial guess: 1

Inputs: None 
----------

Outputs: None 
----------

Examine the display of opspec1 to see that the corresponding property value of opspec1 also changes from 0 to 2.

opspec1
 Operating point specification for the Model watertank.
 (Time-Varying Components Evaluated at time t=0)

States: 
----------
(1.) watertank/PID Controller/Integrator/Continuous/Integrator
	 spec:  dx = 0,  initial guess: 2
(2.) watertank/Water-Tank System/H
	 spec:  dx = 0,  initial guess: 1

Inputs: None 
----------

Outputs: None 
----------

To create an independent copy of an operating point specification, use the copy command.

opspec3 = copy(opspec1);

Now, when you change a property of opspec3, opspec1 does not change. For instance, change the initial value for the first state from 2 to 4.

opspec3.States(1).x = 4
 Operating point specification for the Model watertank.
 (Time-Varying Components Evaluated at time t=0)

States: 
----------
(1.) watertank/PID Controller/Integrator/Continuous/Integrator
	 spec:  dx = 0,  initial guess: 4
(2.) watertank/Water-Tank System/H
	 spec:  dx = 0,  initial guess: 1

Inputs: None 
----------

Outputs: None 
----------

In opspec1, the corresponding value remains 2.

opspec1.States(1).x
ans = 2

This copy behavior occurs because operspec is a handle object. For more information about handle objects, see Handle Object Behavior (MATLAB).

You can create new operpoint variables in three ways:

  • Using the operpoint command

  • Using assignment with the equals (=) operator

  • Using the copy command

Using the = operator results in linked variables that both point to the same underlying data. Using the copy command results in an independent operpoint object. In this example, create operpoint objects both ways, and examine their behavior.

mdl = 'watertank';
open_system(mdl);
op1 = operpoint(mdl)
 Operating point for the Model watertank.
 (Time-Varying Components Evaluated at time t=0)

States: 
----------
(1.) watertank/PID Controller/Integrator/Continuous/Integrator
      x: 0            
(2.) watertank/Water-Tank System/H
      x: 1            

Inputs: None 
----------

Create a new operating-point object using assignment with the = operator.

op2 = op1;

op2 is an operpoint object that points to the same underlying data as op1. Because of this link, you cannot independently change properties of the two operpoint objects. To see this, change a property of op2. For instance, change the value for the first state from 0 to 2. The change shows in the States section of the display.

op2.States(1).x = 2
 Operating point for the Model watertank.
 (Time-Varying Components Evaluated at time t=0)

States: 
----------
(1.) watertank/PID Controller/Integrator/Continuous/Integrator
      x: 2            
(2.) watertank/Water-Tank System/H
      x: 1            

Inputs: None 
----------

Examine the display of op1 to see that the corresponding property value of op1 also changes from 0 to 2.

op1
 Operating point for the Model watertank.
 (Time-Varying Components Evaluated at time t=0)

States: 
----------
(1.) watertank/PID Controller/Integrator/Continuous/Integrator
      x: 2            
(2.) watertank/Water-Tank System/H
      x: 1            

Inputs: None 
----------

To create an independent copy of an operating-point object, use the copy command.

op3 = copy(op1);

Now, when you change a property of op3, op1 does not change. For instance, change the value for the first state from 2 to 4.

op3.States(1).x = 4
 Operating point for the Model watertank.
 (Time-Varying Components Evaluated at time t=0)

States: 
----------
(1.) watertank/PID Controller/Integrator/Continuous/Integrator
      x: 4            
(2.) watertank/Water-Tank System/H
      x: 1            

Inputs: None 
----------

In op1, the corresponding value remains 2.

op1.States(1).x
ans = 2

This copy behavior occurs because operpoint is a handle object. For more information about handle objects, see Handle Object Behavior (MATLAB).

Introduced before R2006a