Page 1 of 1

Problems using some MATLAB functions

Posted: Wed Mar 06, 2024 6:02 am
by manon5683
Hello there,

I am trying to write a script on MATLAB but I encounter problems. The objective of this code would be to:
- plot normalized fiber length
- plot velocity fiber
- plot muscle activation
- plot tendon length
In relation to time (from a model and an associated motion), for each muscle of triceps surae muscular group (med_gas_r, lat_gas_r, soleus_r).

I have loaded the model and the motion. On OpenSim, I directly made the Static Optimization and Analyse. Thus, on my computer, I have some files .STO with data.

As a first step, I tried to use the function getNormalizedFiberLength but I obtained the following error:
"Incorrect number or types of inputs or outputs for function getNormalizedFiberLength."

- Does this function actually exist on MATLAB?
- Have you some examples of scripts doing that? I didn't find on internet.
- Or can you tell me how use this function correctly, please?

- Also, which function can I use to extract the velocity fiber and the muscle activation please?
I found getTendonLength for the tendon length.

On my script, I have written the following lines for importing the libraries:
% Import OpenSim libraries
import org.opensim.modeling.*
opensimLibPath = 'C:\Users\Juliet M\Desktop\OpenSim 4.4\sdk\';
javaaddpath(opensimLibPath);

- Maybe there is something missing?

Also, on my script, getMuscles() works but maybe it is not necessary for what I want to do.

I really need an explanation.

I thank you very much in advance, I will be very grateful for your help! :D

Juliet

(I am using MATLAB 64-bit, OpenSim 4.4 on Windows)

Re: Problems using some MATLAB functions

Posted: Wed Mar 06, 2024 7:58 am
by tkuchida
The activation for each muscle can be found in the states file. You can use a MuscleAnalysis (https://simtk.org/api_docs/opensim/api_ ... ml#details) to generate additional files containing muscle-related quantities, including the other quantities you have listed.

Re: Problems using some MATLAB functions

Posted: Thu Mar 07, 2024 2:26 am
by manon5683
I thank you a lot for replying and for this information. I read that but I still don't fully understand.
Could you detail a little bit what I have to write on MATLAB concretely, please?
What types of inputs or outputs I have to write for the function getNormalizedFiberLength()?

Re: Problems using some MATLAB functions

Posted: Thu Mar 07, 2024 7:18 am
by tkuchida
If you use a MuscleAnalysis, OpenSim will generate separate output files containing the normalized fiber lengths, etc. for you. If you wish to compute these quantities manually, you will need to set the state of the model from the data in the states file one row at a time and then call getNormalizedFiberLength() on each muscle of interest (https://simtk.org/api_docs/opensim/api_ ... 1ba0c50bbc). A rough algorithm might look something like this:

Code: Select all

load the model and call initSystem()
read the states file
for each row in the states file
    set the state of the model
    for each muscle in the model
        normalizedFiberLength_forThisMuscle_atThisTimePoint = thisMuscle.getNormalizedFiberLength(state);
    end for
end for

Re: Problems using some MATLAB functions

Posted: Fri Mar 08, 2024 1:53 am
by manon5683
Ok I thank you very much for your help!!!!