The GShell class

MATLAB provides almost complete support for Java from the command line and in MATLAB functions as well as in methods written using m-code.

When Waterloo is installed, classes supplied as part of the Groovy runtime are also accessible directly from MATLAB.

The GShell supplements this with a set of static methods for compiling and running scripts written purely in Java or Groovy. This provides full access to these languages from MATLAB including access to inner classes and features such as thread control.
For example, using GShell we can create a Rectangle2D.Double instance easily:

                        >> import
                        >> GShell.eval('new java.awt.geom.Rectangle2D.Double(0d,0d,10d,10d)')
                        ans =
You can create anonymous functions (called Closures in Groovy and use them multiple times in the script:
                    >> GShell.eval('Closure printSum = { a, b -> return a+b }; printSum(10,2)')

                        ans =

Creating Waterloo charts is easy:
                    >> p = GShell.eval('import kcl.waterloo.plot.*; WPlot.scatter(["XData",1..10,"YData",1..10])')
                        p =
                    >> p.createFrame()
You can also load, compile and run .groovy scripts from file. These can be created in MATLAB, or with one of the many freely available Java/Groocy IDEs such as NetBeans, Eclipse or IntelliJ.
For Groovy, I find IntelliJ has the best code completion support and it includes useful suggestions about writing well-styled Groovy code.

Among the advantages of using .groovy scripts for MATLAB programmers is:

  • They can be incorporated into a Groovy/Java application fairly directly and compiled as part of the project jar file
  • Scripts can be run in other environments such as SciLab.
For further details of GShell, and GraphExplorer which adds a GUI, see the Groovy API web-pages.