odehybrid
by An Uncommon Lab

vector_to_state

Build a state from a state vector by recursively moving through the elements of a more complex example state (matrix, cell array, or struct), placing the relevant numerical values from the vector into the appropriate places. This is used in odehybrid to convert a state vector into the original complex setup of states. The reverse function is state_to_vector.

state = vector_to_state(vector, state);

Inputs

vectorA vector containing the numerical values from the object
stateA numeric, cell array, or struct array type representing the sizes and types for the values in vector

Outputs

stateA numeric, cell array, or struct array type

Example

state1 = [1 3; 4 2];
state2 = struct('a', {5; 6}, 'bcd', {7:9; 10});
state3 = pi;
x = {state1, state2, state3};
v = state_to_vector(x)
v =
    1.0000
    4.0000
    3.0000
    2.0000
    5.0000
    7.0000
    8.0000
    9.0000
    6.0000
   10.0000
    3.1416
x2 = vector_to_state(v, x)
x2 = 
    [2x2 double]    [2x1 struct]    [3.1416]
isequal(x, x2)
ans =
     1

See Also

state_to_vector