Translating python API code to matlab

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Brian Horsak
Posts: 3
Joined: Fri Sep 08, 2017 4:00 am

Translating python API code to matlab

Post by Brian Horsak » Wed Apr 28, 2021 12:21 pm

Hi,

I am just starting to use the opensim API for matlab. I have a line of code in python which I am trying to convert to matlab. However, I missing a specific part for the matlab code. I was trying now for hours to get a results and finally ended up with getting help here in the forum : ) Any hints more than appreciated:

Python version:
femContact = osimModel.getContactGeometrySet().get('femur_cartilage')
femContactMesh = osim.PropertyString_getAs(femContact.getPropertyByName('mesh_file')).getValue()

What I was not able to find in Matlab was the part 'PropertyString_getAs' - does anyone have an idea how this needs to be done in matlab?

Thank you, Brian

Tags:

User avatar
Ayman Habib
Posts: 2252
Joined: Fri Apr 01, 2005 12:24 pm

Re: Translating python API code to matlab

Post by Ayman Habib » Mon May 03, 2021 11:27 am

Hello,

Not sure what version of openSim code/API you're using but what you need to do is something along the lines below in version 4.0+:

Code: Select all

femContact = osimModel.getContactGeometrySet().get('femur_cartilage') #will return a ContactGeometry
meshContact = osim.ContactMesh.safeDownCast(femContact) # make it into a proper ContactMesh that's aware of mesh files
femContactMeshFile = meshContact.get_filename(0) # get mesh file name from ContactMesh 
You should check the doxygen documentation (accessible through the GUI/Application and/or methodsview() in Matlab) of the version you're using to find out what methods/classes are available.

Best regards,
-Ayman

POST REPLY