Products & Services Solutions Academia Support User Community Company

Learn more about SimMechanics   

mech_set_states - Populate SimMechanics states in Simulink state vector

Syntax

X = mech_set_states(vector_mgr)
X = mech_set_states(vector_mgr, X)
X = mech_set_states(vector_mgr, X, mech_states)

Description

X = mech_set_states(vector_mgr) returns the Simulink state vector X for the model associated with vector_mgr. The state vector entries corresponding to the SimMechanics states are filled with the values specified in vector_mgr. Entries in X that do not correspond to SimMechanics states are set to their initial values, as reported by Simulink.

X = mech_set_states(vector_mgr, X) overwrites the entries that correspond to SimMechanics states in the input state vector X with the values specified in vector_mgr. Entries of X that do not correspond to SimMechanics states are left unchanged. Specify [] in place of X to obtain the initial values for the nonmechanical states, as reported by Simulink.

X = mech_set_states(vector_mgr, X, mech_states) overwrites the entries that correspond to SimMechanics states in the input state vector X with the values specified in mech_states (for example, as reported by vector_mgr.X). Entries of X that do not correspond to SimMechanics states are left unchanged.

Inputs

mech_set_states accepts one, two, or three inputs.

vector_mgr

An instance of the object class MECH.StateVectorMgr corresponding to the machine. This input is required.

X

A vector of Simulink state values. This input is optional.

mech_states

A vector of the mechanical state values, assigned to vector_mgr.X. This input is optional and requires the second optional input, X.

Outputs

X

The Simulink state vector for the model you are querying, with the mechanical state values set to the values specified by the function.

Example

Setting Mechanical State Values

Set state values in a simple pendulum model:

open mech_spen
vm = mech_stateVectorMgr('mech_spen/Machine Environment');
vm.x = [pi/4 0];
simulinkState = mech_set_states(vm);
IS = simset('InitialState',simulinkState);
[t, xIS] = sim('mech_spen', 5, IS);

Compare the initial condition xIS(1,:) with that obtained without setting the initial state in x0(1,:):

[t, x0] = sim('mech_spen', 5);

See Also

mech_get_states | mech_runtime_states | mech_stateVectorMgr | mech_transfer_states | sim | states

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS