OpenSim V3.3 MATLAB API Manual Scaling Append

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Sierra Foley
Posts: 4
Joined: Sun Sep 18, 2022 7:00 pm

OpenSim V3.3 MATLAB API Manual Scaling Append

Post by Sierra Foley » Thu Jul 06, 2023 1:07 pm

Hello,

I have a template XML scale setup file and a MATLAB script that changes model filenames, output file names, start/stop time, and .TRC files. I am manually scaling the femur and tibia and want to have the script changes these values in the .XML file as well. I used the below code to properly create the scaleset for the 4 manual scales; however, it outputs this scale set into a separate XML file. How can I 1. replace the existing scale set in my template XML file with this one OR 2. Just change the scales in my template XML file?


CODE FOR CREATING SEPARATE SCALE SET:

Code: Select all

%ADD MANUAL SCALING FOR FEMUR AND TIBIA
ModelSCL=scaleTool.getModelScaler()

b=scaleTool.getModelScaler()
AS=ArrayStr();
AS.setSize(2);
AS.setitem(0,'measurements');
AS.setitem(1,'manualScale');
b.setScalingOrder(AS);

%SET UP MANUAL 
scaleToolManual=ScaleSet();
scaleToolManual.setSize(700);

for i =1:4
    if i==1;
        name='femur_r'
        SFvec=Vec3(1.5,1.5,1.5)
    elseif i==2
        name='femur_l'
        SFvec=Vec3(2.5,1.5,1.5)
    elseif i==3
        name= 'tibia_r'
        SFvec=Vec3(3.5,1.5,1.5)
    elseif i==4
        name='tibia_l'
        SFvec=Vec3(4.5,1.5,1.5)
    end
    S(i)=Scale;
    S(i).setSegmentName(name)
    S(i).setScaleFactors(SFvec)
    scaleToolManual.cloneAndAppend(S(i))
end
scaleToolManual.print('scale_set.xml')

Tags:

User avatar
Sierra Foley
Posts: 4
Joined: Sun Sep 18, 2022 7:00 pm

Re: OpenSim V3.3 MATLAB API Manual Scaling Append

Post by Sierra Foley » Fri Jul 07, 2023 8:04 am

Solved the issue I was having. Posting the solution as a reply in case others need. Following the code in the previous post, set the Scale set file to the new file/scale set that the for loop creates. ModelSCL was defined previously in the code and is also listed below. Note this is not complete code, but just what was relevant to this particular question.

Code: Select all

% Initialize the scale tool with the default setup file
scaleTool = ScaleTool([genericSetupFilesPath genericSetupFile_fn]);

...
ModelSCL=scaleTool.getModelScaler();

...

scaleToolManual.print('scale_set.xml'); %CREATES TEMPORARY SCALE SET TO BE ADDED TO TEMPLATE
ModelSCL.setScaleSetFile('scale_set.xml') %CHANGES TEMPLATE TO NEW MANUAL SCALE SET

POST REPLY