Page 1 of 1

Accessing model properties through Matlab API

Posted: Fri Sep 23, 2016 12:32 pm
by smithn27
Hi there - I am new to the OpenSim-Matlab interface! I'd like to do a few calculations in Matlab, using values from my scaled OpenSim model - scaled from gait2392.

Using "strengthScaler.m" (comes in the OpenSim download package) as a starting point, I have managed to read in muscle property values (OptimalFiberLength and MaxIsometricForce) from my scaled model. I would also like to use the API to read in properties of the model's bodies. Specifically, I would like the mass of each body so that I can sum them to create a whole_body_mass variable in Matlab. Since the masses of bodies is contained in the .osim file, ideally I'd like to use something as simple as "model_bodies = currentModel.getBodies" but I can't seem to find commands that will:
A) result in a list of bodies in the model; and then
B) report the mass of those bodies

Any help would be greatly appreciated! Thank you in advance - Nate

Re: Accessing model properties through Matlab API

Posted: Fri Nov 04, 2016 2:26 pm
by jimmy
Hi, Nate-

You could use something like this

Code: Select all

import org.opensim.modeling.*

model = Model('myModel.osim')

% get the set of bodies
bodyset = model.getBodySet

% get number of bodies
nBodies = bodyset.getSize

% get the mass of the first body
mass = bodyset.get(0).getMass