Updating Model State in Matlab

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Brody Hicks
Posts: 32
Joined: Wed Jun 19, 2019 11:55 am

Updating Model State in Matlab

Post by Brody Hicks » Wed Feb 16, 2022 9:13 am

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

Tags:

User avatar
Jacob J. Banks
Posts: 97
Joined: Tue Jul 15, 2014 5:17 am

Re: Updating Model State in Matlab

Post by Jacob J. Banks » Wed Feb 16, 2022 2:27 pm

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

User avatar
Nicos Haralabidis
Posts: 196
Joined: Tue Aug 16, 2016 1:46 am

Re: Updating Model State in Matlab

Post by Nicos Haralabidis » Wed Feb 16, 2022 5:24 pm

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

POST REPLY