Hello,
I using the StatesReporter Analysis tool to export the model states for some data I am looking at.
I am then trying to load my model into Matlab, and assign the states exported from the StatesReporter, then loop through the states for each time step and perform some calculations at that state.
Does anyone know how to do this?
Thanks,
Brody
Updating Model State in Matlab
- Brody Hicks
- Posts: 32
- Joined: Wed Jun 19, 2019 11:55 am
- Jacob J. Banks
- Posts: 97
- Joined: Tue Jul 15, 2014 5:17 am
Re: Updating Model State in Matlab
https://simtk.org/projects/emg_opt_tool
The EMGopt_OS40.m script from this project should give you a general idea of the procedure. Let me know if you have any questions.
Jake Banks
The EMGopt_OS40.m script from this project should give you a general idea of the procedure. Let me know if you have any questions.
Jake Banks
- Nicos Haralabidis
- Posts: 196
- Joined: Tue Aug 16, 2016 1:46 am
Re: Updating Model State in Matlab
Hello Brody,
I have taken some of the code you posted in relation to a previous post linked to this matter. I think that should do the trick!
states_sto = Storage(statesPath);
stateTrajectory = StatesTrajectory.createFromStatesStorage(model,states_sto);
nRows = stateTrajectory.getSize();
% Assuming your model is called model
myState = model.initSystem();
calcn_r = model.getBodySet.get('calcn_r'); %get body reference
for n = 0:nRows-1
state = stateTrajectory.get(n); %now I have a reference to the current state
% Populate state vector for each loop iteration
model.setStateVariables(myState,state);
model.realizePosition(state);
rotation = calcn_r.getTransformInGround(state).R();
quat = rotation.convertRotationToQuaternion();
calcn_rotation(n+1,:) = [quat.get(0) quat.get(1) quat.get(2) quat.get(3)];
end
I have taken some of the code you posted in relation to a previous post linked to this matter. I think that should do the trick!
states_sto = Storage(statesPath);
stateTrajectory = StatesTrajectory.createFromStatesStorage(model,states_sto);
nRows = stateTrajectory.getSize();
% Assuming your model is called model
myState = model.initSystem();
calcn_r = model.getBodySet.get('calcn_r'); %get body reference
for n = 0:nRows-1
state = stateTrajectory.get(n); %now I have a reference to the current state
% Populate state vector for each loop iteration
model.setStateVariables(myState,state);
model.realizePosition(state);
rotation = calcn_r.getTransformInGround(state).R();
quat = rotation.convertRotationToQuaternion();
calcn_rotation(n+1,:) = [quat.get(0) quat.get(1) quat.get(2) quat.get(3)];
end