Matlab

The software provided on this page has been tested with Matlab version 5, and 6 on HP-UX, Solaris, Linux, and Windows (MinGW) and Matlab version 7 on Windows.

A history of my Matlab Central File Exchange submissions can be found here.

Matlab Widget Toolkit

MTk is a high-level command line interface for creating graphical user interfaces using Handle Graphics. MTk is for people who don't need a guide to write graphical user interfaces.

Below is the code of MTk's Tab Panel demo. As you can see, only three commands are needed to build a whole GUI.

     f = mtk('figure', 0, '0x0', ...
             'Name', 'MTk Demo: Tab Panel', ...
             'Resize', 'off', ...
             'Visible', 'off');

     mtk('render', f, ...
         {'vbox' ...
          'Margin' 16 ...
          'Padding' 16 ...
          {'tabs' ...
           {'tab' ...
            'Caption' 'First' ...
            {'vbox' ...
             'Margin' 8 ...
             {'text' ...
              'String' 'Hello world!'}}} ...
           {'tab' ...
            'Caption' 'Second' ...
            {'vbox' ...
             'Margin' 8 ...
             {'text' ...
              'String' 'Good by sailor!'}}} ...
           {'tab' ...
            'Caption' 'Third' ...
            {'box' ...
             'Margin' 8 ...
             {'tabs' ...
              {'tab' ...
               'Caption' 'Fourth' ...
               {'vbox' ...
                'Margin' 8 ...
                {'group' ...
                 'Caption' 'Fruits:' ...
                 {'vbox' ...
                  'Margin' 8 ...
                  {'checkbox' ...
                   'String' 'Apples'} ...
                  {'checkbox' ...
                   'String' 'Bananas'}}}}} ...
              {'tab' ...
               'Caption' 'Fifth' ...
               {'vbox' ...
                'Margin' 8 ...
                {'text' ...
                 'String' 'The end.'}}}}}}} ...
          {'hbox' ...
           'Pack' 'center' ...
           {'pushbutton' ...
            'String' 'Close' ...
            'Callback' 'delete(gcbf);'}}});

     set(f, 'Visible', 'on');

Here is the result. Isn't that nice.

extern/mtk-tab-panel.png

Parse Command Options

The getopt command parses options from an argument list. The aim is to be close to GNU long options functionality, and beyond.

Here is an example, for how to use getopt.

     function foo(varargin)

       % Initialize options.
       opt = getopt(5);

       for ind = 1:numel(opt)
         switch ind
          case 1
           opt(ind).name = '-flag';
           opt(ind).type = 'flag';
          case 2
           opt(ind).name = '-mode';
           opt(ind).type = 'char';
           opt(ind).choices = {'box', 'line'};
           opt(ind).values = [4, 2];
           opt(ind).value = 4;
           opt(ind).assign = 1;
          case 3
           opt(ind).name = '-color';
           opt(ind).type = 'color';
          case 4
           opt(ind).name = '-cursor';
           opt(ind).type = 'cursor';
          case 5
           opt(ind).name = '-fullcross';
           opt(ind).type = 'alias';
           opt(ind).index = 4;
           opt(ind).value = 'fullcrosshair';
          otherwise
           error('Should not happen');
         end
       end

       % Parse options from argument list.
       [opt, arg] = getopt(opt, varargin{:});

Rubber-Band Selection

Select a figure or axes region.

This rubber-band command has a lot of customization options, for example, rubber-band mode (box, x, y, line), optional display of cursor coordinates, free selection of color, line style, marker symbol, and figure cursor, axes expansion, choice of return values (points, vectors, rectangle), and the type of rendering for animated objects.

The rubberband command depends on the getopt command (see above).

Here is an example for how to it.

     x = linspace(0, 2 * pi);

     subplot(2, 1, 1);
     plot(x, sin(x));
     axis tight;

     subplot(2, 1, 2);
     plot(x, cos(x));
     axis tight;

     [p1, p2] = rubberband('-mode=x', '-coord', '-expand=y');
extern/rubberband.png

Text File Printing

Convert text file for printing.

The textpr command converts a text file for printing. Paper size, page layout, n-up printing, basic formatting, and output file format can be customized via command line options.

The textpr command depends on the getopt command (see above) and a Ghostscript executable (like the one shipped with older versions of Matlab).

Configuration Utilities

The m-config package provides GNU Autoconf macros checking for Matlab features and platform incompatibilities. Documentation and a complete example project are included in the package.

See the Matlab Configuration Utilities manual, for more details.

m-config is free software and distributed under the GNU General Public License.

Directory Stack

The m-dirs package provides the directory stack commands as known from various Unix shells for Matlab. Available Matlab commands are dirs, pushd, and popd.

Command names and usage is equal to the Unix shell commands:

     >> pwd
     ans =
     /tmp
     >> pushd /usr/bin
     /usr/bin
     /tmp
     >> pwd
     ans =
     /usr/bin
     >> popd
     /tmp
     >> pwd
     ans =
     /tmp

m-dirs is free software and distributed under the GNU General Public License.

Regular Expressions

The m-regex package provides POSIX regular expressions for Matlab. Available Matlab commands are regcomp, regnsub, regexec, regfree, regerror, and regnomatch.

Command names and usage is equal to the POSIX functions:

     pattern = '[aeiou]+';
     [regex, code] = regcomp(pattern, 'x');
     if code ~= 0
       error(regerror(code, regex));
     end
     fprintf('Pattern `%s'' has %d sub-expression(s)\n', ...
             pattern, regnsub(regex));

     strings = {'foo', 'bar', '42'};
     for i = 1:length(strings)
       string = strings{i};
       [match, code] = regexec(regex, string);
       if code == regnomatch
         fprintf('Pattern `%s'' does not match `%s''\n', ...
                 pattern, string);
       elseif code ~= 0
         error(regerror(code, regex));
       else
         substr = string(match(1).so:match(1).eo-1);
         fprintf('Pattern `%s'' matches `%s'' in `%s''\n', ...
                 pattern, substr, string);
       end
     end

     regfree(regex);

m-regex is free software and distributed under the GNU General Public License. If your system has no native support for POSIX regular expressions, m-regex uses the GNU equivalent which is distributed under the GNU Library General Public License.

User Interface

The m-ui package provides wrappers for Matlab's uicontrol and uimenu family of commands. It simplifies building Matlab graphical user interfaces a lot (in case you can not or do not like to use guide):

     f = ui_figure([100 100 200 150]);

     ui_frame(f, [0 0 100 100]);
     ui_frame(f, [100 0 100 100]);
     ui_frame(f, [0 100 200 50]);

m-ui is free software and distributed under the GNU General Public License.

Top of this Page