**Ian Searle**

The title says it quite succinctly. The purpose of this article is
to explain why *you* might want to use RLaB as opposed to
Matlab. This purpose of this article is not to belittle Matlab
instead, I will try and point out the differences between the two
programs, and consequently why you may, or may not, want to use
RLaB. I have organized this article into three sections. The first
is an attempt to discuss the similarities present in the two
programs. The second section is an attempt to present a strictly
technical argument. While the third section is left for everything
else.

I would like this article to be as objective as possible,
even considering who it is written by. If you feel that I have
unfairly criticized Matlab or drawn invalid comparisons, please feel
free to write me at `ians@eskimo.com`

to express your opinions.

Both programs are Very High Level languages (VHLL) oriented towards
applied mathematics. As languages, both offer numerical and string
variables and arrays, conditional and flow-control constructs, and
functions. Both programs offer an interface to the more popular
linear algebra functions available through
Netlib^{1}. Both programs offer convenient
visualization of data through two and three dimensional plotting
functions.

As VHLL with convenient data visualization, both programs offer an environment for numerical computation, experimentation, and algorithm development that is generally more productive that the traditional develop--compile--link--run--debug cycle we are all familiar with.

Now I will attempt to point out the technical differences between the two programs.

- The Matlab language supports one data type, the matrix. The
matrix is used to represent scalars, vectors (1-D arrays), and
matrices (2-D arrays). The matrix is also used to represent
vectors of characters, and matrices of characters. Matlab
versions 4.x added a sparse matrix. Any numerical matrix can
be either real or complex.
RLaB offers more than the matrix as a data type. However, the matrix is probably the most often used data structure. Like Matlab, RLaB's matrices are used to represent scalars, vectors, and matrices, both real and complex. At this point in time RLaBdoes not offer a sparse matrix.

In addition to the matrix, RLaB has a string class, and data type. A string is a variable length collection of characters. Both string vectors, and string matrices are supported. One advantage to the addition of this type is the ability to collect strings of different lengths in the same vector or matrix.

However, the most significant improvement is RLaB's

*list*class. A list is a heterogeneous associative array that can contain any data type, including other lists. The list gives RLaBusers the opportunity to structure their data as necessary. Some possible uses are:- Lists can be used to store vectors or matrices of
differing sizes that need similar processing. For
example, you might have several vectors of differing
length, each representing some time-series data. You
might want to process them all in a similar fashion,
such as apply spectral transformations or collect
statistics. In Matlab you are forced to use separate
vectors, or some special functions to ``pack'' the
vectors into a dense or sparse array. In RLaByou can
simply create a list containing each vector:
for (i in 1:N) { ldata.[i] = readm ("datafile." + num2str (i)); }

Now the list,

`ldata`

can be passed to a function for processing:`process_data (ldata)`

. - Lists can be used to store data ``objects''. For
example: suppose we are performing simulations of
dynamic systems. We might represent our system as a
state-space model. Typically a state-space model
consists of four coefficient matrices:
. Instead of handling each matrix as a distinct
matrix, we could group them together, and use functions
to operate upon each state space model as a whole:
ss1 = ss_create ( freqv, dampv ) // Create a state-space model // from frequencies and damping. ss1.bode = ss_bode ( ss1, IN, JW ) // Compute Bode plot for state-space // model.

In these situations the list helps the user/programmer organize the data in sensible ways that can reduce confusion.

- The heterogeneous nature of lists will become more
apparent as we look at this last example. RLaBhas a
function called getline, which is somewhat like the AWK
getline function. Getline gets a line of ASCII text from
a file, parses the line on whitespace, and returns the
results in a list, where the first element contains the
contents of the first field, the second element contains
the contents of the second field, and so on. Getline is
smart enough to distinguish numbers from ordinary text,
and the returned list can contain both types of
objects
^{2}.In this example we will read a data-file that contains some test output. The engineer doing the test annotated each row of test output with a label. We would like to maintain the label, and use it from within RLaB. The file looks like:

sensor1 0.162 0.665 0.0847 0.204 0.167 sensor2 0.655 0.129 0.91 control 0.112 0.299 0.265 0.7

We can read this data, and maintain the strings as labels by:

> while (length (line = getline ("test.data"))) { test_data.[line.[1]] = get_test_vector (line); } > test_data test_data = control sensor1 sensor2 > test_data.sensor1 sensor1 = 0.162 0.665 0.0847 0.204 0.167

As you can see, the data is now stored in a list, with element names from the first field of

`test.data`

. Each element is a numeric vector, which contains the rest of the data in each row.`get_test_vector`

is a simple nine-line function that returns all but the first element as a vector.

- Lists can be used to store vectors or matrices of
differing sizes that need similar processing. For
example, you might have several vectors of differing
length, each representing some time-series data. You
might want to process them all in a similar fashion,
such as apply spectral transformations or collect
statistics. In Matlab you are forced to use separate
vectors, or some special functions to ``pack'' the
vectors into a dense or sparse array. In RLaByou can
simply create a list containing each vector:
- Matlab functions have some severe (in my opinion)
limitations:
- Only one function is allowed in a file.
- Function arguments are passed by value. This in itself
is not good or bad. However it is somewhat limiting to only
allow one method.
- All variables, except those declared global are
local. There are only two scoping possibilities. There is no
way to hide data (data abstraction).

In RLaB, we try to overcome these limitations with the following:

- Users can put as many function definitions in a file as
desired, there are no limitations.
- Function arguments can be passed by value and reference.
- In addition to global and function-local variables,
there are also file-static variables. Variables can be
declared static within a file. These variables are hidden from
the global environment and other files. Only the functions
within the file (and after the declaration) have access to the
variable.

- Only one function is allowed in a file.
- Matlab and RLaB also differ some in Input/Output (I/O)
capabilities. Both offer ASCII and binary I/O for all types of
data. However, RLaB offers the ability to read and write
through pipes. Any function that takes a filename as an
argument can also be given a process to read or write data
to or from. For example:
`fprintf`

can be used to send commands or data to a processfprintf ("| gnuplot", "plot %s using 1:3\n", tmp_file_name);

Or

`readm`

can be used to read the output of a filter on some pre-existing data.x = readm ("| awk -f data_filter.awk < orig_data");

- Matlab has a ``Fortran-ish'' style syntax. RLaB has a C style
syntax. This is a matter of personal preference.
- RLaB and Matlab offer a different method of statement
evaluation. The MathWorks does not explicitly discuss the
language expression evaluation, so it is hard to tell what the
intent is. My limited experience suggests that Matlab is
composed of ``special-cases''. Whatever the internal
construction, the end effect is the user must remember more
syntactic idiosyncrasies with Matlab, than with many other
languages.
In RLaB expressions usually (most always) have a result. You can figure out for yourself what the result of a particular statement will be by evaluating each sub-expression, starting at the lowest level, and combining the results, until you have the answer. Sometimes this is called a substitution model of evaluation. When using RLaB there

*should*be less idiosyncrasies to deal with. - Matlab and RLaB offer mostly the same mathematical
operators. The two sets of operators differ in only a few
instances. RLaB has extended the operator set slightly with
an element-by-element multiply, divide, add, and subtract that
allow users to operate row-by-row or column-by-column.
- In the area of data visualization (plotting) Matlab and RLaB differ dramatically. Matlab offers a comprehensive graphical
capability that does not stop at plotting data. In addition to
striking two and three dimensional plots, Matlab offers the
more sophisticated users the ability to create their own
graphical applications with common graphical ``widgets'' such
as: buttons, sliders, text entry, and more.
RLaB offers a much simpler data visualization capability. RLaB graphics are handled through a scientific graphics library called Plplot. The Plplot API is implemented as a set of builtin functions within RLaB. Thus, the high level plotting capabilities are handled by RLaB programs. Two and three dimensional plots, contours, and histograms, with a host of options are supplied. Custom plots are can be created by utilizing the low-level Plplot API. The most popular output devices (screens and printers) are supported. When using X-windows, there is a nice ``plot-widget'' that allows the user to zoom and pan, print plots, and tweak the color-maps.

If you need really ``gee--whiz--turbo--object--oriented'' graphics, you ought to be looking at Matlab. If you need a good programming language that offers good data visualization, then RLaB deserves a look.

- Matlab's linear algebra functions are based upon the sources
from the LINPACK and EISPACK projects. It would be ridiculous
of me to criticize these functions as MathWorks has
modified/improved them over the years, and certainly there is
no one better equipped to do so than Cleve Moler.
RLaB's linear algebra functions are mostly supplied by the source code from the LAPACK project. LAPACK could be called ``LINPACK

`+`

EISPACK Edition''. The LAPACK functions offer some block structured algorithms, and utilize levels 2 and 3 BLAS. Thus, on some machines they may provide better performance.

- Starting off with a rather practical consideration--where can
you run these programs? Matlab is available from the Mathworks for
most Unix workstations, MS-Windows PCs, Apple Macintoshes, VAXes
and some super/mainframe computers (such as the Cray and
Convex). Matlab is not available for OS/2, and some of the less
popular Unix workstations. If Mathworks does not support or
discontinues support for a particular platform, you can ask them
to reconsider--generally you will be out of luck. Mathworks
charges a substantial fee for use of their product. On some
platforms the fee must be payed yearly.
RLaBis available in binary and source-code formats. Since you can get the source code, you can port it to any platform you like. There are no charges for using RLaB. You can get free support from the RLaBuser's group, and the author. If you want more reliable support, you can pay someone (usually a consultant).

Some would feel that RLaBis better as a long term tool, since they have the source code and can run the program on most any computer without restriction. Others would feel that since Matlab is commercially supported/developed that it is more reliable as a long term tool.

- Another practical consideration. You may be in the position to
purchase some of Mathwork's toolboxes. These toolboxes are
collections of popular numerical procedures and algorithms. There
are quite a few toolboxes available: signal processing, controls,
neural-networks, image-processing, etc ... These toolboxes are
mostly in the form of Matlab mfiles, so that you can look at them
to understand how they work. For the most part these toolboxes are
*not*meant to be used as black-boxes.RLaBdoes not offer the same selection of toolboxes, either commercial or contributed. There is a growing number of contributed rfiles, and a controls, testmatrix, and signal-processing collections are in the works. But RLaB will never match Matlab's volume of toolbox material. If you are a student or in the position of writing most of your own procedures, then this may not matter much to you.

There is no way to summarize exept to say: decide for yourself. The choice is not simple, and it is worth careful consideration, since both programs can have a significant impact upon the way you do your work/learning.

This document was generated using the
**LaTeX**2`HTML` translator Version 99.2beta6 (1.42)

Copyright © 1993, 1994, 1995, 1996,
Nikos Drakos,
Computer Based Learning Unit, University of Leeds.

Copyright © 1997, 1998, 1999,
Ross Moore,
Mathematics Department, Macquarie University, Sydney.

The command line arguments were:

**latex2html** `-no_navigation -split 0 rlab-why`

The translation was initiated by Ian R. Searle on 2000-01-09

- ... Netlib
^{1} - netlib.att.com
- ... objects
^{2} - Strtod and num2str functions exist in case you are able to fool getline.

Ian R. Searle 2000-01-09