Using Jython extension in MATLAB

Source: Internet
Author: User

The object-oriented capability in MATLAB is not strong, and its function can be extended by using the Jython engine.


1 edit classpath.txt and add Jython. Jar

Input in MATLAB

Which classpath.txt

Result:

/Usr/local/Matlab/r2013a/toolbox/local/classpath.txt

Edit the file and add

/Home/your_user/jython2.5.3/Jython. Jar

2. Restart MATLAB 3 and write the code for testing.
import javax.script.Invocable;  import javax.script.ScriptEngine;  import javax.script.ScriptEngineManager;  mg = ScriptEngineFactory();jy = mg.getEngineByName('jython')
You can see the result:

JY =

[Email protected]

jy.eval('print("Hello")')jy.eval('def add(a, b):\n   return a + b')jy.eval('add(5, 5)')jy.put('name', 'Hello')jy.get('name')v = rand(5, 5)jy.put('vals', v)jy.get('vals')

If you want to use other script engines, such as JavaScript, refer to the previous blog article. 4. Call the Jython interpreter to call the Python code file.
import org.python.util.PythonInterpreterintp = PythonInterpreter();intp.exec('a = 5;')intp.get('a');


But in fact, the exec method and the method in 3 are functionally consistent;

Considering the interface consistency of javacripengine, we recommend that you use the method in step 3.


Using Jython extension in MATLAB

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.