Page 1 of 1

Static Optimization in Matlab

Posted: Fri Jan 14, 2022 12:57 am
by frabottin
Hi everyone,
I am running Static Optimization with the Matlab API. In my simulations, I have to increase the external force to find the value at which SO fails. Is there a way to automatically get if SO failed or not as an output, without manually reading the command window at each simulation?

Thanks in advance,
Francesca

Re: Static Optimization in Matlab

Posted: Fri Jan 14, 2022 5:33 am
by tkuchida
You should also be able to retrieve this information by checking the out.log and err.log files (renamed to opensim.log as of v4.2; see https://simtk-confluence.stanford.edu:8 ... d=48988768). To detect a certain behavior automatically, you could load this file and search for a particular string.

Re: Static Optimization in Matlab

Posted: Sun Jan 16, 2022 9:45 pm
by johnjdavisiv
I have a small MATLAB script that I've developed for exactly this purpose. I put together a demo repository on GitHub that uses the Rajagopal 2015 data and my log parsing function, you can check it out here.

It uses the new Logger() class so I think it will only work in OpenSim 4.3+. You can set the file name of the log to correspond to whatever file you are processing, then the function outputs a processed .csv with a column indicating which timestamps, if any, static optimization failed. It should be pretty easy to adapt for your purposes!

Re: Static Optimization in Matlab

Posted: Mon Jan 17, 2022 10:20 am
by frabottin
Thanks for the replies.
@John Davis, thank you for sharing the script. I converted my code to 4.3, adapted your script to my case and it worked!