| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → SimMechanics |
| Contents | Index |
| Learn more about SimMechanics |
X = mech_set_states(vector_mgr)
X = mech_set_states(vector_mgr, X)
X = mech_set_states(vector_mgr, X, mech_states)
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.
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. |
X |
The Simulink state vector for the model you are querying, with the mechanical state values set to the values specified by the function. |
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);
mech_get_states | mech_runtime_states | mech_stateVectorMgr | mech_transfer_states | sim | states
![]() | mech_runtime_states | mech_stateVectorMgr | ![]() |

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 |