Using import org.opensim.modeling.*
 Anthony Santago
 Posts: 15
 Joined: Mon Feb 15, 2010 11:33 am
Using import org.opensim.modeling.*
I'm attempting to learn about the Matlab OpenSim interface from the OpenSim 3.0 beta and am having trouble developing a model instance. I believe that Matlab is not importing the org.opensim.modeling.* correctly. However, I wanted to make ensure that I was following the protocol correctly before contacting Mathworks. I'm using Matlab R2011A. Below is my code:
import org.opensim.modeling.*
scaleFactor = 1.0;
dir = 'C:\Users\asantag\Documents\OpenSim 3.0\sdk\Matlab\testData\Subject01';
cd(dir);
Model_In = ['subject01_gait2392','_scaled.osim'];
Model_Out = 'subject01_gait2392_scaled_Altered.osim';
Model1 = Model(Model_In);
Error message:
??? Undefined function or method 'Model' for input arguments of type 'char'.
I believe this is indicating that Matlab does not recognize that this is a C++ command and it trying to find the function "Model" in its path definition.
import org.opensim.modeling.*
scaleFactor = 1.0;
dir = 'C:\Users\asantag\Documents\OpenSim 3.0\sdk\Matlab\testData\Subject01';
cd(dir);
Model_In = ['subject01_gait2392','_scaled.osim'];
Model_Out = 'subject01_gait2392_scaled_Altered.osim';
Model1 = Model(Model_In);
Error message:
??? Undefined function or method 'Model' for input arguments of type 'char'.
I believe this is indicating that Matlab does not recognize that this is a C++ command and it trying to find the function "Model" in its path definition.
 Romain LEBERRE
 Posts: 12
 Joined: Fri Feb 24, 2012 11:47 am
Re: Using import org.opensim.modeling.*
Hi,
I had a similar problem with version 2.4.0. I realized that I was using Matlab 64 bits while OpenSim was a 32 bits version. Now it works fine with Matlab 32 bits.
Also make sure that you have set up Matlab to access the Java wrapper to Opensim. It is well explained in the readme I enclosed given in https://simtk.org/home/matlab_tools.
Hope this helps
I had a similar problem with version 2.4.0. I realized that I was using Matlab 64 bits while OpenSim was a 32 bits version. Now it works fine with Matlab 32 bits.
Also make sure that you have set up Matlab to access the Java wrapper to Opensim. It is well explained in the readme I enclosed given in https://simtk.org/home/matlab_tools.
Hope this helps
 Attachments

 ReadmeAPI.txt
 (3.17 KiB) Downloaded 223 times
 Anthony Santago
 Posts: 15
 Joined: Mon Feb 15, 2010 11:33 am
Re: Using import org.opensim.modeling.*
Thank you for your reply.
I added the exact lines below
"C:\OpenSim 3.0\opensim\modules\orgopensimmodeling.jar" to the classpath.txt
"C:\Opensim3.0\bin" to librarypath.txt
"C:\Opensim3.0\bin" to the pathdef file
when I tried to run the following code
model = org.opensim.modeling.Model();
I received the following error
Java exception occurred:
java.lang.UnsatisfiedLinkError: org.opensim.modeling.opensimModelJNI.swig_module_init()V
at org.opensim.modeling.opensimModelJNI.swig_module_init(Native Method)
at org.opensim.modeling.opensimModelJNI.<clinit>(opensimModelJNI.java:6475)
at org.opensim.modeling.Model.<init>(Model.java:110)
I'm running a 32 bit matlab on a 64 bit windows machine. Can you direct me to the appropriate version of java to download?
I added the exact lines below
"C:\OpenSim 3.0\opensim\modules\orgopensimmodeling.jar" to the classpath.txt
"C:\Opensim3.0\bin" to librarypath.txt
"C:\Opensim3.0\bin" to the pathdef file
when I tried to run the following code
model = org.opensim.modeling.Model();
I received the following error
Java exception occurred:
java.lang.UnsatisfiedLinkError: org.opensim.modeling.opensimModelJNI.swig_module_init()V
at org.opensim.modeling.opensimModelJNI.swig_module_init(Native Method)
at org.opensim.modeling.opensimModelJNI.<clinit>(opensimModelJNI.java:6475)
at org.opensim.modeling.Model.<init>(Model.java:110)
I'm running a 32 bit matlab on a 64 bit windows machine. Can you direct me to the appropriate version of java to download?
 Ayman Habib
 Posts: 2238
 Joined: Fri Apr 01, 2005 12:24 pm
Re: Using import org.opensim.modeling.*
Hi Anthony,
I'd recommend you follow the steps on the support site below for version 3.0 as they're more updated.
http://simtkconfluence.stanford.edu:80 ... ith+Matlab
Your error message suggests that the OpenSim dlls are not found on your path, while the jar file has been located properly. Did you call editpath as described on the page above?
Please make sure you use the exact full path (spaces included if any) as in your message it appears that the change in librarypath.txt uses "OpenSim3.0" while the class path change uses "OpenSim 3.0" with extra space after OpenSim.
Please let us know how it goes so we can update the instructions if needed. Just in case, what's your version of Matlab?
Ayman
I'd recommend you follow the steps on the support site below for version 3.0 as they're more updated.
http://simtkconfluence.stanford.edu:80 ... ith+Matlab
Your error message suggests that the OpenSim dlls are not found on your path, while the jar file has been located properly. Did you call editpath as described on the page above?
Please make sure you use the exact full path (spaces included if any) as in your message it appears that the change in librarypath.txt uses "OpenSim3.0" while the class path change uses "OpenSim 3.0" with extra space after OpenSim.
Please let us know how it goes so we can update the instructions if needed. Just in case, what's your version of Matlab?
Ayman
 Anthony Santago
 Posts: 15
 Joined: Mon Feb 15, 2010 11:33 am
Re: Using import org.opensim.modeling.*
Ayman
Thank you for your response. I had to reinstall OpenSim in addition to altering my windows settings. I had to change my settings so that windows did not query me to ask whether or not software could access the C: drive. Thank you for your help. I'm currently using Matlab 2012b.
Thank you for your response. I had to reinstall OpenSim in addition to altering my windows settings. I had to change my settings so that windows did not query me to ask whether or not software could access the C: drive. Thank you for your help. I'm currently using Matlab 2012b.
 Ayman Habib
 Posts: 2238
 Joined: Fri Apr 01, 2005 12:24 pm
Re: Using import org.opensim.modeling.*
Hi Anthony,
Great that you got around your problems. I'm not sure exactly what you changed where (in Windows permissions? or Matlab?) to get going but it would be great if you can post the details (what commands you used, where) so that other users with similar problems can benefit from your successful experience.
All the best,
Ayman
Great that you got around your problems. I'm not sure exactly what you changed where (in Windows permissions? or Matlab?) to get going but it would be great if you can post the details (what commands you used, where) so that other users with similar problems can benefit from your successful experience.
All the best,
Ayman
 Anthony Santago
 Posts: 15
 Joined: Mon Feb 15, 2010 11:33 am
Re: Using import org.opensim.modeling.*
Matlab was having trouble accessing the C: drive because of my Windows 7 User Account Control Settings. Basically, Matlab needed administrator permission to access the C: drive and was incapable was asking for permission for whatever reason. If you have performed all of the instructions and are still having problems running the interface I would recommend doing the following
Control Panel\All Control Panel Items\User Accounts
then press on the link called "Change user account control settings"
Move the bar all the way to the bottom so it says "never notify"
Control Panel\All Control Panel Items\User Accounts
then press on the link called "Change user account control settings"
Move the bar all the way to the bottom so it says "never notify"
 Sina Porsa
 Posts: 99
 Joined: Thu Feb 03, 2011 7:21 pm
Re: Using import org.opensim.modeling.*
Hi dear Aymanaymanh wrote:Hi Anthony,
I'd recommend you follow the steps on the support site below for version 3.0 as they're more updated.
http://simtkconfluence.stanford.edu:80 ... ith+Matlab
Your error message suggests that the OpenSim dlls are not found on your path, while the jar file has been located properly. Did you call editpath as described on the page above?
Please make sure you use the exact full path (spaces included if any) as in your message it appears that the change in librarypath.txt uses "OpenSim3.0" while the class path change uses "OpenSim 3.0" with extra space after OpenSim.
Please let us know how it goes so we can update the instructions if needed. Just in case, what's your version of Matlab?
Ayman
I followed all the steps in above mentioned link. I edited classpath.txt and librarypath.txt and also added c:\OpenSim 3.0\bin to the path.
After restarting the Matlab I tested to check if everything is ok. I typed "model = org.opensim.modeling.Model();" in matlab command window and it created a model object, which I suppose means that everything is configured correctly.
But when I want to run the example *.m files (e.g. OpenSimCreateTugOfWarModel.m) Matlab returns this error:
Required library failed to load. Check that the dynamic library osimJavaJNI is in your PATH. java.lang.UnsatisfiedLinkError:\OPenSim 3.0\bin\osimJavaJNI.dll: The specified procedure could not be found.
Regards,
Sina
 Sina Porsa
 Posts: 99
 Joined: Thu Feb 03, 2011 7:21 pm
Re: Using import org.opensim.modeling.*
Hi All
I just understood how to solve the problem.
If i launch MatLab from start menu and the change MatLab working directory to the folder which contains the m files, everything will work. But if I double click on the m file to launch MatLab, it returns the above mentioned error.
I just understood how to solve the problem.
If i launch MatLab from start menu and the change MatLab working directory to the folder which contains the m files, everything will work. But if I double click on the m file to launch MatLab, it returns the above mentioned error.
 Mohammad S. Shourijeh
 Posts: 2
 Joined: Wed May 13, 2009 8:43 am
Re: Using import org.opensim.modeling.*
Hello,
I faced with a similar issue. I am running Windows764bit, Java 7 Update 21, and MATLAB 2013a 32bit.
I followed all the steps detailed in the following link:
http://simtkconfluence.stanford.edu:80 ... ith+Matlab
but I got this error message window when executing "model = org.opensim.modeling.Model();":
"Required library failed to load. Check that the dynamic library osimJavaJNI is in your PATH
java.lang.UnsatisfiedLinkError: C:\OpenSim 3.0\bin\osimJavaJNI.dll: The specified procedure could not be found"
As mentioned by Ayman, the dll file is located at the bin folder, so it is misleading.
When I close that error window, this error is printed on the Command Window:
start of the error
Java exception occurred:
java.lang.UnsatisfiedLinkError:
org.opensim.modeling.opensimModelJNI.swig_module_init()V
at org.opensim.modeling.opensimModelJNI.swig_module_init(Native
Method)
at
org.opensim.modeling.opensimModelJNI.<clinit>(opensimModelJNI.java:8014)
at org.opensim.modeling.Model.<init>(Model.java:118)
end of the error
I tried different things, including Java reinstallation and installing OpenSim 3.1 beta and following the steps for 3.1 version. I also tried "never notify" setting, mentioned by Anthony, but the issue still exists.
Can anyone think of a workaround?
By the way, editpath does not apparently work anymore; if you still want to use the command window, "pathtool" works for all MATLAB versions.
Thanks,
Mohammad
I faced with a similar issue. I am running Windows764bit, Java 7 Update 21, and MATLAB 2013a 32bit.
I followed all the steps detailed in the following link:
http://simtkconfluence.stanford.edu:80 ... ith+Matlab
but I got this error message window when executing "model = org.opensim.modeling.Model();":
"Required library failed to load. Check that the dynamic library osimJavaJNI is in your PATH
java.lang.UnsatisfiedLinkError: C:\OpenSim 3.0\bin\osimJavaJNI.dll: The specified procedure could not be found"
As mentioned by Ayman, the dll file is located at the bin folder, so it is misleading.
When I close that error window, this error is printed on the Command Window:
start of the error
Java exception occurred:
java.lang.UnsatisfiedLinkError:
org.opensim.modeling.opensimModelJNI.swig_module_init()V
at org.opensim.modeling.opensimModelJNI.swig_module_init(Native
Method)
at
org.opensim.modeling.opensimModelJNI.<clinit>(opensimModelJNI.java:8014)
at org.opensim.modeling.Model.<init>(Model.java:118)
end of the error
I tried different things, including Java reinstallation and installing OpenSim 3.1 beta and following the steps for 3.1 version. I also tried "never notify" setting, mentioned by Anthony, but the issue still exists.
Can anyone think of a workaround?
By the way, editpath does not apparently work anymore; if you still want to use the command window, "pathtool" works for all MATLAB versions.
Thanks,
Mohammad