I am extremely pleased to host guest blogger Christopher Albert. Chris and his colleagues created and maintain the enormously-interesting (IMHO) and complex Matclipse project, which connects Java’s popular Eclipse IDE with Matlab.
The open-source matclipse project is an interface between the Java integrated development environment (IDE) Eclipse and Matlab. It was developed at the Institute for Theoretical and Computational Physics (ITP) at Graz University of Technology (TU Graz) by a team that consisted of David Camhy, Winfried Kernbichler, Georg Huhs and Christopher Albert. Matclipse is part of a bigger endeavor, namely, the development of the teaching and learning environment MatlabTutor. It is released under the Eclipse Public License (full text).
The aim of the project is to facilitate the usage of Matlab directly from Eclipse under various operating systems (Linux, Windows, OS X). At the moment, it consists of a workbench, an Matlab editor, a Matlab console including a command window and a viewer for results, a Matlab command history and a Matlab workspace viewer.
The matclipse project is hosted on Google Code. Unfortunately, it does not contain a lot of external documentation, except a somewhat-outdated wiki, with installation instructions. A list of open issues is maintained here, where you can also report new issues. There is also a newsgroup forum/mailing-list with some activity.
The Matlab workbench uses a tree structure for workspace. One can create Matlab projects there and, of course, all basic features from Eclipse are supported there. Projects can have a Matlab nature and files can be executed directly from the workbench without opening them in the editor.
Communication with Matlab
At the moment, the communication between Java and Matlab is based on the usage of pipes under Linux and OS X and on the usage of DCOM under Windows. In both cases it is necessary to have a local installation of Matlab. An extension to enable communication with a remote Matlab server is planned for the future but various issues (see below) have to resolved for a successful implementation of this feature.
In Linux as well as OS X there is no documented way of access to Matlab, to its memory and to its variables. For that reason, the most reliable way of communication was the usage of pipes. Since in this case, memory in Matlab and memory in Eclipse is strictly separated, any transfer of variables from Matlab to Eclipse needs time and doubles the amount of necessary memory. Therefore, this is not the best of all ways but without the help of MathWorks no other possibility is feasible. Under the operating system Windows, MathWorks provides DCOM as a possibility to control Matlab.
With pipes a remote access to Matlab on a remote Linux server is possible because pipes can be established through a ssh-tunnel. In addition, a remote file system from this server has to be mounted in Eclipse. A good candidate for this seems to be a ssh-based file system. This would enable the storage of programs directly from the editor on the server where Matlab could execute them.
Additional problems arises if graphical output is produced in Matlab or if Matlab tools like the help browser or the profile viewer has to be used. One way to handle this problem is the installation of an X11 server on the client which could display all additional windows from the server on the client through the X11 protocol in case of a correct setting of the display variable. Beside issues of security and speed, technically everything could run as on a local machine but the requirement is a reliable X11server used by Eclipse on the client side.
Another possibility to use a remote server is the conversion of Matlab figures to pictures (e.g. PNG) and to transfer those pictures through the pipe back to the client. The task of eclipse then would be to provide a viewer for this pictures. Of course, any interaction with the figures in a Matlab kind of way (zooming in and out, rotation, etc.) would not be possible. It would also require some overhead to detect what figures are new or have been modified to keep the time for transfer as low as possible. Also bookkeeping for figures has to be established to be able to remove deleted figures from the picture viewer. With the restrictions mentioned above this is possible. A usage of the help browser and profile viewer would not be possible in this case. Ideally, the user could have a choice between both methods.
The Matlab editor is based on a regular expression parser which provides syntax highlighting and checking. A new Xtext-based version had been under development but was not been brought to a usable state due to the limitations of the features and performance of the Xtext framework.
The current features are:
- Smart indentation and parenthesis matching.
- Detection of variables, operators, strings, commands and key words.
- Integration of the Matlab program mlint to mark errors and warnings directly in the editor.
Possible improvements for the future could be:
- Syntax highlighting with detection of all Matlab commands also from available toolboxes. The list of these commands has to be extracted from the Matlab help directory for a given version of Matlab. Commands from Matlab directly and from toolboxes can be shown in different colors.
- Direct link to Matlab help pages locally or situated at MathWorks.
- Evaluation of the whole file or of a selection of lines directly in Matlab.
- Export of a documented file in XML, Latex, PDF or HTML format. With syntax highlighting, indentation and links to Matlab help.
- Usage of a simple wiki-like markup language to display mathematical formulas, lists
In contrast to Matlab where input to and output from Matlab is displayed in the same window, matclipse uses a concept with a separate command line for input to Matlab and a results viewer for displaying the output from Matlab nicely separated by the input commands. This concept proved to be practical but has its limitations.
The current features of the command line are the following:
- Syntax highlighting is provided by the editor.
- Up- and down-scrolling in the command history.
- The Matlab command input had to be overwritten with a version which opens an input dialog box (inputdlg) in a modal Matlab window. There was no other way to enable the user to provide the input to Matlab. This is a clear disadvantage when using a remote server because this solution for sure requires a X11 server to display the modal window.
- The Matlab command pause without an additional time specified had to be overwritten. It is terminated now automatically after 2 seconds because there was no way to terminate the pause from the command line. In future one would have to think of an icon (or a shortcut) which would terminate the pause in similar way as CTRL-C is handled to stop execution of a command.
- CTRL-C does not work in the command line. An icon was provided in the console to stop execution of Matlab.
- Icons are provided to start and stop Matlab.
- Additional icons are available to bring figures in the foreground or to delete figures.
- There is a possibility to change the Matlab directory without a Matlab command.
- One can start the Matlab help browser from an icon.
- One can clear the results view from an icon (clc does not work).
- One can toggle Matlab console debug from an icon, to debug the XML communication between matclipse and Matlab. Note that this debug mode does not enable debugging the Matlab code itself – perhaps this will be added in the future.
Additional disadvantages and plans for the future are summarized here.
- When scrolling up or down the lines with %- should not be shown in the command line.
- When scrolling up or down one should be able to write some letters before starting to scroll. In this case one should get only a limited choice. E.g., if one writes plo one should only get command lines from history which start with these letters, like plot(x,y).
- This feature could be extended to allow for wildcards. E.g., if one writes *sin one should get only lines which contain sin at some position.
- Copy and Paste should be enabled with shortcuts everywhere. At the moment one needs the context menu for this.
- One should cycle round when reaching the end or the beginning of the command history.
- The Matlab command clc should be parsed and it should not be send to Matlab. Instead, the results view should be cleared.
- The Matlab command edit or edit(filename) should be parsed and it should not be send to Matlab. Instead, one should be placed in the correct editor window. If the filename does not exist, it should be created. If the Matlab extension *.m does not exist it should be added automatically.
- In addition to the icon for the Matlab help browser there should be an icon for the Matlab profile viewer.
- A debug mode should be enabled. This would require an integration of the editor into this task.
- At the moment, the workspace viewer is updated after each execution of the command line. This results in a time delay which gets bigger when there is a larger Matlab workspace. This update should only happen when the user switches to the tab with the workspace view. Otherwise, if the workspace view is not used, unnecessary time is wasted with the update.
- Sometimes there is the problem that Matlab is busy when the user tries to execute a script. This might be in connection with the use of mlint directly from the editor. The context menu Save and Run forces saving of the file which triggers mlint and then tries to execute the script. Maybe one has to wait until mlint is finished or it should be clearly shown to the user that the script could not be executed. Now this is sometimes confusing.
Matlab Command History
The Matlab history records commands which are executed for further usage. The data are stored in sections with different starting times of a working session. In contrast to Matlab, lines which are used again without any change are not duplicated but moved to the current location. This keeps the list shorter.
In case a couple of lines are executed from the editor with
execute selection, those lines a stored in one entry in the command history and can be recalled at once.
Additional features and fixes are recorded here:
- A selection of more than one line should be possible for execution, deleting and copying.
delete oldto the context menu to erase all entries from previous sessions.
- When there are more commands in one line, one should not show the
\n, one should rather use a space instead for the display and keep it for execution. This is only cosmetics because it just looks ugly.
- Drag and drop to the command window is not really necessary because there exist faster ways with scrolling and the return key.
- The user should be able to collapse selections or everything belonging to some old session. Those things should be stored but not used when scrolling up or down in the command line.
Matlab Workspace Viewer
The Matlab workspace viewer enables the user to explore the Matlab variables. In contrast to Matlab, a tree is used for this view where all data types can be displayed. So called container data types like cells and structures are displayed with there size and then a sub-tree is opened which shows the contents in the container. This is possible for the whole depths of those data types. To save time especially when working with pipes, first only the structure of the workspace is shown in the tree together with size information. The detailed information about the content of an array is only transferred from Matlab to Eclipse when this entry is chosen with the mouse or the keyboard.
To avoid unnecessary transfer of data only a limited amount of data from a big array is requested from Matlab. The selection shows relevant information in a compressed form but never shows 100 x 100 array fully. Typically it shows a first block of data from the array accompanied by the last row and the last line to give a good and compact view on the data.
The exchange of information between Matlab and Eclipse is based on a XML description of the workspace generated within Matlab.
Additional features and fixes are recorded here:
- In addition to class, name and size one could show for numerical arrays the minimum and the maximum as well as the mean value to have a better overview. The appropriate Matlab routines are already modified to provide those information in the XML representation.
- To be able to view the whole content of a numeric data type one could add a context menu which then would transfer all data for this array for display in a style sheet like viewer.
- In the context menu (and with the delete button) one should be able to delete variables. This should be possible only on the first level. So specific content of cells and structures can not be deleted in such a way.
- When selecting one or more variables, it should be possible to edit a plot command which should then be send to Matlab. E.g., if you select the variables x and y then the context menu should open a small editor window with pre-filled commands like figure; plot(x,y). If the user does not like the choice then he can edit this field and finally the command is send to Matlab. There is no need to transfer the data to Eclipse.
- One could imagine a similar feature when selecting two numerical arrays for comparison. For this a Matlab routine could be provided to display the differences and similarities.
Multivariate analysis with Eigenvector
(the following is once again in my (Yair’s) own voice):
I would like to direct readers attention to Eigenvector Research (featured as a sidebar ad on this page). Eigenvector provides Matlab-based solutions for multivariate analysis (MVA) with a specific emphasis on chemical applications, i.e. chemometrics. Their products include the PLS_Toolbox for general MVA/chemometrics, and MIA_Toolbox for Multivariate Image Analysis. They also provide training and consulting services.
If you work with applications that produce large amounts of multivariate data, you may well find their products and services useful.