Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Using Within MATLAB

Daniel P. Dougherty

<IMG SRC="http://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png" ALT="MATLAB Logo" WIDTH="64" HEIGHT="64">

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');


Note that Strings must be singly quoted in the MATLAB syntax, which contrasts with the double quoted Strings expected in native JAVA language.

In an actual MATLAB session the result will look like this:

Snifflib in MATLAB

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

>> HelloSnifflib


Using m-files is one of the most common methods for programming complex tasks using MATLAB.

Snifflib in MATLAB m-file


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:

  • mat2DblMatrix.m
  • DblMatrix2mat.m


Related

Wiki: Home