Manual scaling via matlab scripting

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Donatella Simonetti
Posts: 2
Joined: Tue Jul 23, 2019 5:16 am

Manual scaling via matlab scripting

Post by Donatella Simonetti » Thu Apr 27, 2023 9:52 am

Hello,

I'm trying to scale a generic model 2392 manually but I'm having problems getting to the right solution via Matlab script. Should I use the Model class and the function scale to perform the scaling? Or should I create a ScaleTool? In both cases (see below) I get stuck.
Could you please give me a hint on how to proceed?

Via the Model

Code: Select all

Model2 = Model(generic_model);
Model2.initSystem;

% How do I get the states?  How do I define the scaleSet? 
Model2.scale(states,scaleSet, true, mass);
Model2.print(output);
Via ScaleTool

Code: Select all

scale_tool = ScaleTool(scale_template);
% How do I connect the ScaleTool to a specific model to scale?
scale_tool.setPathToSubject(unscaled_model); 
scale_tool.run();

Tags:

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

Re: Manual scaling via matlab scripting

Post by Thomas Uchida » Thu Apr 27, 2023 3:45 pm

This thread might be helpful (Topic 14302): viewtopicPhpbb.php?f=91&t=14302. Several other relevant posts can be found by searching the Forum for "ScaleTool Matlab".

User avatar
Donatella Simonetti
Posts: 2
Joined: Tue Jul 23, 2019 5:16 am

Re: Manual scaling via matlab scripting

Post by Donatella Simonetti » Fri Apr 28, 2023 12:44 am

Hi Thomas,

thank you for your reply. Now it's working :)

I will leave here the working Matlab function:

Code: Select all

 function manual_scaling(scale_template,unscaled_model,mass, output)
% function to plate IMUs on a Osim model by calling OpenSim functions

import org.opensim.modeling.*

% open generic model
Model1 = Model(unscaled_model);
Model1.initSystem;

% create scale tool object from an exixtent template
scale_tool = ScaleTool(scale_template);
scale_tool.setName('scale_model');
scale_tool.setSubjectMass(mass);
%%% ModelPlacer stuff
scale_tool.getMarkerPlacer().setOutputModelFileName(scale_template); %2 of 2, markers
%%% ModelScaler stuff
scale_tool.getModelScaler().setApply(1)
scale_tool.getModelScaler().setOutputModelFileName(scale_template); %1 of 2, scaling
%%% ModelMaker stuff
scale_tool.getGenericModelMaker().setModelFileName(unscaled_model);

% scaling model
scale_tool.getModelScaler().processModel(Model1, unscaled_model, mass)
% print new model
Model1.print(output)

end

POST REPLY