Using a plugin Analyze Tool in Matlab

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Therese Parr
Posts: 9
Joined: Mon Dec 02, 2019 9:47 am

Using a plugin Analyze Tool in Matlab

Post by Therese Parr » Wed Aug 16, 2023 7:15 am

Hi all,

I am trying to use the plugin 'MuscleForceDirection' within a Matlab code. I have tried two options and want to know if there is any way this can work better.

1. I would love to be able to use the AnalyzeTool within Matlab to run StaticOptimization, MuscleAnalysis, and MuscleForceDirection all together. My code for that looks like:

import org.opensim.modeling.*
opensimCommon.LoadOpenSimLibraryExact('C:\OpenSim 4.4\plugins\MuscleForceDirection.dll');
mfdTool = MuscleForceDirection();
mfdTool.setStartTime(startTime);
mfdTool.setEndTime(endTime);

Loading the OpenSim library returns true so it seems like that worked, however, when trying to actually use the MuscleForceDirection tool, Matlab is still saying that it is an unrecognized function or variable.

2. Alternatively, when following the documentation for the MuscleForceDirection plugin, this code is given:

[message,result] =dos(['analyze -S ',SetupFile,' -L ','MuscleForceDirection.dll'],'-echo');

It seems to run everything, but does so separately from the other analyses so it takes double the time. I also can't edit any of the settings for the tool, such as 'print_muscle_attachments'.

Is there another way I could be calling this plugin to edit and print it to the .xml set up file for AnalyzeTool? Also, how would I find the other proper Matlab commands for settings within the tool since these are not going to be found on the API page?

Thanks in advance!
Reese

Tags:

User avatar
John Davis
Posts: 56
Joined: Mon Aug 26, 2019 7:42 am

Re: Using a plugin Analyze Tool in Matlab

Post by John Davis » Wed Aug 16, 2023 4:51 pm

Hi Reese,

You can use the PropertyHelper class (requires OpenSim 4.2+) to "trick" MATLAB into playing nice with the line of action plugin. You also have to add the directory the .dll file is in. Here is a GitHub gist showing how to do it: https://gist.github.com/johnjdavisiv/26 ... cd84f38123

That gist is meant to run in the same directory as the demo arm motion files that come packaged with the line of action plugin. As long as you have the dll added to the OpenSim library and a "pre-loaded" generic template for the analysis you can dynamically adjust its settings in a MATLAB script, though you need to access a few properties by name vs. by a method (illustrated in the code above).

You might also be interested in this GitHub repo that shows how to run this kind of analysis + visualize the results two different ways. It also showcases a few of the bugs and odd quirks in the output from the line of action tool.

I haven't added the line of action analysis alongside static optimization and muscle analysis (I do them separately) but it might work, and might help speed up the analysis. You'd probably want to start from the muscle line of action template, then tack on the additional analyses with the API. Watch out for the first/last frame bug in the line of analysis tool though (detailed in the github repo above). One reason you might want to separate them: if you have lots of files to plow through, static optimization can be parallelized, but the line of action tool cannot (at least as far as I can tell).

Hope this helps!

User avatar
Therese Parr
Posts: 9
Joined: Mon Dec 02, 2019 9:47 am

Re: Using a plugin Analyze Tool in Matlab

Post by Therese Parr » Fri Aug 18, 2023 7:20 am

Hi John,

Thanks so much for the guidance and code- this was a huge help!

I implemented the code you gave for MuscleForceDirection and it runs great within Matlab. I did start with the MuscleForceDirection template and tacked on the other two analyses (static optimization and muscle analysis) all under AnalyzeTool and they run at the same time now. Additional thanks on the heads up for some future troubleshooting with the MuscleForceDirection tool's bugs.

Reese

POST REPLY