MATLAB and GAMS: Deprecated Versions

Authors: Michael C. Ferris (, Steven Dirkse (, and Rishabh Jain

This document is intended only for users of previous versions of the MATLAB/GAMS and GDXMRW utilities

This may work for older GAMS systems and older versions of MATLAB, but comes with no support or guarantees.

For previous users only: A new interface between MATLAB and GAMS (version 2.0)

We are pleased to announce a new major release of the MATLAB/GAMS interface.

The new interface merges the read and write routines of GDXMRW and the original MATLAB/GAMS interface into one system with three routines:

Placeholders for the deprecated routines (from version 1 of GDXMRW) readgdx.m and writegdx.m are also provided but the user is encouraged to switch to the new, more efficient rgdx and wgdx routines. The routine "gams" is not backwards compatible: calls of the old form:

gams('qp', Q)

must be replaced by (for example) = 'Q'; sQ.val = Q; gams('qp',sQ);

(due to a change by Matlab in the mex interface). There is also a requirement for a "header" line in the GAMS file if you are using output parameters and some changes to the syntax within the GAMS file are needed.

From version 23.4 of GAMS onwards, the MATLAB facilities are provided within the GAMS distribution (download current GAMS distribution) for Windows, Mac and Linux platforms. Simpler installation procedures are provided in the documentation in the GAMS distribution or online at: (GDXMRW new version installation and documentation).

Deprecated ways of interfacing MATLAB and GAMS

Current documentation (for version 008) is available only as a pdf file. Note that this version includes the ability to do execution time over-writing of parameters, and uses a slightly different scheme for passing parameters from MATLAB to GAMS. It is only available for PC, linux and solaris boxes.

Original version of the documentation: Mathematical Programming Technical Report 98-19, November 1998.

Two alternatives for interfacing MATLAB and GAMS

There are two possible ways to interface between Matlab and GAMS. The first mechanism is provided as a download below and allows you to pass data to and from a gams program via parameters to a "gams mex interface". This can be invoked for example as: In this setting "qp.gms" is a GAMS file that contains a few extra lines to facilitate the read-in of Q and the write-out of the solution x. Examples are given in the documentation found above on this page.

The second mechanism is to use the GDXMRW facilities that are available and documented as GDXMRW download. Essentially two mex procedures are provided that read and write a gdx file. A GAMS program can then use built in GAMS procedures to read and write these same gdx files. The invocation in GAMS would be something like:

The writegdx call creates a file q.gdx containing the data that is in the matlab matrix Q. The file qp.gms would read this in using "$gdxin" or execute_load. More details can be found at GDX documentation. The readgdx routine reads the file x.gdx that was created by the qp.gms file into a matlab matrix x. Some helper utilities sp2full and full2sp are provided that help manipulate the input and output data structures (that are basically in i,j,val format) to have the correct (dense) matlab matrix structure.

Download and installation instructions

All the files needed to download this link are available on the ftp site of the Computer Sciences Department at the University of Wisconsin.

Several examples of the use of this link are found in this "zip" file, along with instructions for installation. It is suggested that the archive file "" is unzipped ("unzip") in a new directory.

If you download and use this software, please acknowledge use by citing the above technical report in your work.

Previously used versions are also still downloadable but without any support provided.

Example output

Sample output from a tomotherapy example can be found in PDF form. These pictures are associated with a project described in:
David M. Shepard, Michael C. Ferris, Gustavo Olivera and Thomas R. Mackie
Optimizing the Delivery of Radiation to Cancer Patients.
Mathematical Programming Technical Report 98-07, June 1998.
This file is large since it contains a bunch of postscript figures. Compressed versions are also available for download: UNIX compress, ZIP archive.