MATLAB is one of the most popular and powerful computational and visualization softwares around. The user interface and much of the backend is JAVA and runs in a Java Virtual Maching (JVM). Note, however, that MATLAB ships with its own JVM which will typically be different from the JVM you are using for your own programming.
To get started, you will need to download the latest version of the Snifflib jar. For this example, we assume snifflib-1.7.jar.
MATLAB functionality can be expanded by simply directing its virtual machine to the location of the Snifflib jar and importing the classes you want to use. The first MATLAB command you will need is the javaaddpath command which accepts the path to the jar on your file system.
Next, you should use import statements for the classes you want to use by name in your MATLAB programming. Here is a sample session following the content of the HelloSnifflib.java program used in our previous tutorials.
>> javaaddpath /home/jdoe/lib/snifflib-1.7.jar >> import('com.mockturtlesolutions.snifflib.datatypes.DblMatrix'); >> X = DblMatrix('[1 2 3; 4 5 6; 7 8 9]'); >> X=X.times(DblMatrix.PI); >> X.show('Hello Snifflib');
In an actual MATLAB session the result will look like this:
Alternatively, you might save the above MATLAB code as a script m-file (e.g. HelloSnifflib.m) and run all the commands by simply entering
Using m-files is one of the most common methods for programming complex tasks using MATLAB.
Users wishing to inter-convert between Snifflib's DblMatrix and MATLAB's native matrix classes may be interested in downloading the Snifflib Toolbox for MATLAB. The Snifflib Toolbox consists of MATLAB functions (m-files) which handle the conversions from within a MATLAB session. For example: