Matlab is a native of Java. It has traveled oceans and continents to get to where it is today and it promises you the dream that is interoperability with java classes. Like with most things java, you must first setup the "class path" so that the proper name-spaces are observed. The dynamic path (meaning that you will have to set this up every time and it gets searched last) is managed with the two commands: javaaddpath and javarmpath Some libraries must be included in Matlab's static path, which is located here: <MATLABPATH>/toolbox/local/classpath.txt As an example I will show how to get a Processing 1.1 sketch to work with Matlab 2009b in OSX. To begin, exit Matlab if it is open. Then open Matlab's static class path: <MATLABPATH>/toolbox/local/classpath.txt Add the path of Processing's core.jar to the end of classpath.txt. The path to the Processing files is most likely something like: <PROCESSINGPATH>/Contents/Resources/core.jar Now restart Matlab and you can add dynamic paths to the directories containing your java code. For this example I add two directories: javaaddpath({ Then it is possible to access the java classes in a straightforward way, pretty much like you would if you were just using java. Here is an example m-file: import java.awt.*; import java.awt.event.*; import javax.swing.*; import processing.core.*; % create window in which applet will execute applicationWindow = JFrame( 'An applet running as an application' ); width = 300; height = 200;
% create one applet instance appletObject = jtb.test.matlab_test(width,height-22); % call applet's init and start methods appletObject.init; appletObject.start; % attach applet to center of window applicationWindow.getContentPane.add( appletObject ); % set the window's size applicationWindow.setSize( width, height ); % showing the window causes all GUI components % attached to the window to be painted applicationWindow.show; |
Miscellaneous >