Call Method in Your Own Java Class - MATLAB & Simulink (original) (raw)
Main Content
To define new Java® classes and subclasses of existing classes, use a Java Development Kit external to MATLAB®. For version information, see Versions of OpenJDK Compatible with MATLAB by Release.
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 folderC:\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 yourprefdir
folder.