# Using the MATLAB API

## Quick start

The MATLAB API- Emulates the standard MATLAB graphics library (line, scatter commands etc) for creating plots.
- Allows MATLAB and Waterloo graphics to be mixed in a single MATLAB figure

The MATLAB API therefore provides a quick route for experienced MATLAB programmers to try out Waterloo and easily convert existing code to use it.

## BUT

**This API adds Java graphics to standard MATLAB figures. There is no guarantee that this will be possible in future versions of MATLAB.**For production-code, or code that needs to be future-proof, this API is best avoided. Use the Groovy API or Java API instead.

## Creating a figure

Create a figure using the*GXFigure*command:

% Create a MATLAB figure that % is 'Waterloo enabled' f = GXFigure();At instantiation, a GXFigure has no graphs associated with it. Calling

*gxgca*(see right) will create one, and return a reference to the it. Alternatively, use subplot as described below.

## Subplots

GXFigures support subplots in the same way as MATLAB figures. To create a Waterloo subplot, pass the reference of the GXFigure as the first input to the subplot commmand, e.g.f = GXFigure(); g = subplot(f,2,2,1);creates a 2 x 2 grid of graphs and selects the first as the current graph just as with the standard MATLAB subplot command. The returned reference,

*g*, is a Waterloo GXGraph instance - roughly equivalent to a MATLAB axes instance.

To add standard MATLAB plots to a GXFigure,
call subplot *without* specifying the GXFigure,
e.g. for the figure above:

g = subplot(2,2,2);will create a standard MATLAB axes at position 2.