Editing the XML file using Matlab

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Sheeba Davis
Posts: 56
Joined: Sat Mar 23, 2019 5:19 am

Editing the XML file using Matlab

Post by Sheeba Davis » Tue Mar 09, 2021 1:41 am

Hi

I have some doubts w.r.t editing my scale setup file.

I have added the first "Marker pair" to my "Marker pair set" and then to the "Measurement-torso". Similarly, "Body scale" to "Body scale set" to "Measurement-torso". With this, i have created my first "Measurement-torso". Next when i want create second "Measurement-pelvis" , i could change the marker names in the already existing "Marker Pair". But when i use "cloneAnd Append", the new "Marker pair" gets appended to the old "Marker pair" in the "Measurement" instead of replacing it.

What command do i need to use to replace the "Marker pair" in the "Measurement"?

Thanks in advance.
Sheeba

Tags:

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

Re: Editing the XML file using Matlab

Post by Ayman Habib » Thu Mar 11, 2021 10:18 am

Hello,

MarkerPair has a method

Code: Select all

setMarkerName(int i, String aName)
which is used to set the names. In general you should consult the doxygen documentation to see what methods are available for each object, for example here:

https://simtk.org/api_docs/opensim/api_ ... rPair.html

Hope this helps,
-Ayman

User avatar
Sheeba Davis
Posts: 56
Joined: Sat Mar 23, 2019 5:19 am

Re: Editing the XML file using Matlab

Post by Sheeba Davis » Fri Mar 12, 2021 9:03 pm

Hi Ayman

Thanks for the clarification. I am getting to understand much better now.

Regards
Sheeba

User avatar
Sheeba Davis
Posts: 56
Joined: Sat Mar 23, 2019 5:19 am

Re: Editing the XML file using Matlab

Post by Sheeba Davis » Mon Mar 15, 2021 11:02 pm

Hi

In continuation with the process of editing "myScale" (Scale Setup file), i have created a "MeasurementSet" and appended it to "myScale". Next time when i wanted to append "ScaleSet" to "myScale" (on some other day), i just did:

Code: Select all

import org.opensim.modeling.*
myScale = ScaleTool();
myScale.getModelScaler().getScaleSet().setName('gait2354_Scale');
myScale.print('myScale.xml');
But what happens is, the whole file of "myScale" becomes blank (empty file, that means whatever i had done previously is gone) and only the ScaleSet name has been set <ScaleSet name="gait2354_Scale">

Can you please tell me why this happens?

Regards
Sheeba

User avatar
Thomas Uchida
Posts: 1793
Joined: Wed May 16, 2012 11:40 am

Re: Editing the XML file using Matlab

Post by Thomas Uchida » Tue Mar 16, 2021 7:38 am

In your code, you are creating a new ScaleTool object, setting a string, and then saving to file---presumably overwriting the file you had saved eariler. If you want to modify an existing file, you need to read that file in as the starting point (something like myScale = ScaleTool('myScale.xml'); rather than myScale = ScaleTool();).

User avatar
Sheeba Davis
Posts: 56
Joined: Sat Mar 23, 2019 5:19 am

Re: Editing the XML file using Matlab

Post by Sheeba Davis » Tue Mar 16, 2021 8:08 am

Hi Thomas

Thanks for your response. It was indeed a great help. Now it works fine. I did'nt know that we could do that way.

Regards
Sheeba

User avatar
Sheeba Davis
Posts: 56
Joined: Sat Mar 23, 2019 5:19 am

Re: Editing the XML file using Matlab

Post by Sheeba Davis » Fri Mar 19, 2021 2:50 am

Hi

In continuation with the process of editing an xml file, i would like to know the matlab command for setting the value type in the IK coordinate task. In case of default value, there was no issue, but if i have to set value type to "ManualValue", i am unsure of its argument. i do not know whether i should use StringToValueType for converting to the required value type.

Thanks in advance
Sheeba.

User avatar
Thomas Uchida
Posts: 1793
Joined: Wed May 16, 2012 11:40 am

Re: Editing the XML file using Matlab

Post by Thomas Uchida » Fri Mar 19, 2021 6:15 am

Please refer to the API documentation for the ScaleTool class (https://simtk.org/api_docs/opensim/api_ ... eTool.html). Also, as described on the "Scripting with Matlab" page in the documentation (https://simtk-confluence.stanford.edu/d ... ith+Matlab), you can use the "methodsview()" function in Matlab to display all the methods available for an OpenSim object.

User avatar
Sheeba Davis
Posts: 56
Joined: Sat Mar 23, 2019 5:19 am

Re: Editing the XML file using Matlab

Post by Sheeba Davis » Sun Mar 21, 2021 10:35 pm

Hi Thomas

Thanks for your reply. I have gone through API documentation, scripting with matlab and also used methodsview(). I am actually trying to recreate the the scale setup file for gait2354 model provided in the OpenSim 4.1 distribution in matlab. The 'ValueType' in the IKCoordinateTask for 'lumbar extension' is to be set to 'manual_value'. I used:

Code: Select all

>> methodsview IKCoordinateTask
The 'setValueType' has an argument 'org.opensim.modeling.IKCoordinateTask$ValueType'. For ex, in case of a 'default_value', i dint have to do 'setValueType':

Code: Select all

>> MtpAngleLIKCoordinateTask=IKCoordinateTask ();
MtpAngleLIKCoordinateTask.setName('mtp_angle_l');
MtpAngleLIKCoordinateTask.setApply(true);
MtpAngleLIKCoordinateTask.setWeight(1000.00000000);
myScale.getMarkerPlacer().getIKTaskSet().cloneAndAppend(MtpAngleLIKCoordinateTask);
and i got

<IKCoordinateTask name="mtp_angle_l">
<apply>true</apply>
<weight>1000</weight>
<value_type>default_value</value_type>
<value>0</value>
</IKCoordinateTask>
It must be some small change i need to incorporate, but unable to figure it out.

Thanks
Sheeba

POST REPLY