This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Call Method in Your Own Java Class

To define new Java® classes and subclasses of existing classes, use a Java Development Kit external to MATLAB®. For information on supported versions of JDK™ software, see the MATLAB Supported Language Interfaces website.

After you create class definitions in .java files, use your Java compiler to produce .class files. The next step is to make the class definitions in those .class files available for you to use in MATLAB.

This example shows how to call a method in your own Java class. The example uses a class file named myclass.class in the folder C:\Documents\MATLAB\ containing a method package.myclass.mymethod(params).

Put the class file on the dynamic Java class path, making the class available in the current MATLAB session only. MATLAB provides the dynamic path as a convenience for when you develop your own Java classes.

  • Add the class to the dynamic Java class path. To access the class, you must modify the Java path every time you start MATLAB.

    javaaddpath('C:\Documents\MATLAB\')
  • Call the method. Substitute your own class file name and path, and call the method with the appropriate parameter list.

    package.myclass.mymethod(params)
  • Make the class always available in MATLAB. Add it to the static class path by editing the javaclasspath.txt file in your prefdir folder.

See Also

Related Topics

External Websites