wp44edafb4_1b.jpg

Antennas and Microwaves

wp6f846985_1b.jpg

Matlab and alternatives from an MS Windows viewpoint.   

Original post 2008, last updated Feb 2010

 

CONTENTS

Matlab

Why Alternatives

The Candidates

     Jmathlib

     Octave

     Freemat

     Scilab

Conclusions

 

Almost every scientist or engineer will at some point need to do a little number crunching that requires a bit more than a calculator or an Excel spreadsheet. Matlab has undoubtedly become the standard by which others are judged, if only because of the number of other packages that purport to emulate it or be an equal to it.

 

MATLAB

 

I have used Matlab in a professional environment for around 12 years and found it to be an excellent tool. As its name suggests the unit of operation is a matrix, with which you can do just about anything, then plot the result in just about any form. However, the real power of Matlab is in its architecture, using the famous m-files.

 

Apart from being able to operate Matlab directly from the command line, sequences of instructions can be stored in files with a “.m” extension. Once the file is saved you just tell Matlab which directory to find it in, your m-file has now become part of the Matlab language!

 

To run the file you just type the name at the command prompt, or you can use it in another m-file. There is no real distinction between m-files that define specific functions (with input & output parameters) and those that are just sequences of commands (scripts). The first section of uninterrupted comment lines in the m-file automatically becomes the help file.

 

It all sounds incredibly easy, and it is, which is why Matlab has become so popular. At the end of the day all languages are going to have their little idiosyncrasies regarding command syntax. What sets one apart from another is how easy it is to get those commands doing something useful for you.

 

WHY ALTERNATIVES

 

So, having sung Matlab’s praises, why look for alternatives? The answer for me is cost and accessibility. Using Matlab is great if you only want to share the end results of your work. Trying to share m-files that produced the results immediately limits your audience to those people who can afford or who have access to Matlab.

 

I would prefer to be able to write small utility programs that can run on something that is freely available on the web. However, the chosen platform needs to get at least close to Matlab in the ease of use department – no one likes a pain in the arse, even if it’s free!

 

Here is a list of some of the qualities I’ve been looking for:

 

  1. Ease of installation – ideally available for Win98/XP/Vista/Win7 using self-extracting installers.
  2. Well integrated – not collections of shareware held together with binary glue.
  3. Easy to compile / run – if I want spend all day looking for and linking library files, I’ll use C.
  4. User Interface – needs to be intuitive, so will probably look like most other Windows apps.
  5. I/O – data is rarely typed in these days so file, DAQ and GPIB support if possible.
  6. Documentation – well-written manuals and help files are essential.
  7. Support – good host site with evidence that there are plenty of other users.

 

 

 

THE CANDIDATES

 

Here are the packages I’ve looked at so far. I cannot claim to have used them all in real anger, but that is partly due to shortcomings in some of the categories listed above. I haven’t included links to the sites, just type the name into Google, the home site is almost certainly on the first page.

 

JMATHLIB (v0.9.4)

 

Well there seem to be huge numbers of references to sources for the download, and the home site promises good things. On the up side there was a single self extracting installer, on the down side the resulting installation did nothing apart from briefly display a logo. (I tried on Win XP / 98 & 95). As a result it failed the “ease of installation test”. A trawl of the web using search strings such as “jmathlib forum” now reveals that I am not the only one who has had difficulties. It appears that the Windows installer puts all the necessary bits on your computer but then it’s very much up to you to get the Java to run. Unless you’ve had some experience of setting up Java and writing scripts, you are probably going to end up  looking for the haemorrhoid cream with this one.

 

OCTAVE (v3.2.3)

 

The last time I tried this I was looking for something that would still run on Win98, the version I found was v2.1.50 which installed easily on Win98 and XP. Apart from a few difficulties with calling up Notepad (the default text editor), the main difficulties I saw for the Windows user centred around the very non-Windows-like user interface.

 

Moving on to v3.2.3, there has obviously been a lot of development going on in terms of the internals, the installation now takes up a whopping 359MB of disk space. This rather precluded any more experiments on my Win98 based machine so this evaluation is limited to use with XP. The installation is now very Windows-like in that there is no more DOS prompt with yes/no questions, instead there are tick boxes asking if any additional modules are to be installed, much like Matlab. However, don’t get too excited and start reaching for the mouse just yet, our old friend Cygwin is still in evidence (a UNIX style interface that sits on windows). As a result the user interface is pretty much unchanged from v2.1.50 and remains a fairly stark place to be if you’re used to lots of drop down menus.

 

Looking through the installation directory (the default is C:\Octave) the folders are now much better organised and the documentation is easier to locate (C:\Octave\3.2.3_gcc-4.4.0\doc). The individual function help works as per Matlab and there are very comprehensive pdf and HTML help files in the afore mentioned directory. The default editor is now Notepad++, a Windows compatible text editor with a bias towards program editing, and is readily invoked from the command line by typing “edit”. Plotting is via GNU plot and is sufficiently well integrated as to be transparent to the user; scaling, labels and line styles etc are all accessible directly from the Octave environment.  

 

Octave uses m-files and is basically trying to copy Matlab and to this end it does well in the “easy to compile / run” requirement. The default search directory for m-files is (C:\Octave\3.2.3_gcc-4.4.0\share\octave\3.2.3\m). To add new search directories you will need to use the addpath.m file and type ‘path’ at the command prompt to check the current list of search paths. At the risk of playing devil’s advocate, I tried adding a search path that pointed directly to my own Matlab toolbox (Rfutils) and just ran the examples. The examples involve a fair amount of number crunching and graphics output and all executed  to completion, albeit with warnings and some graphics output differences.

 

Matlab files running on Octave

After my limited experimentation I would have to say that Octave has now reached a point where simple m-files, by which I mean not too adventurous with graphics or data formats, could port with relative ease from Matlab to Octave. Despite this, I’m not sure how many Matlab users will be rushing  to convert their code, even if the required changes are minor.

 

Octave files running on Matlab

Since Octave could be loosely regarded as a subset of the Matlab language, writing m-files in Octave to run directly in Matlab should be relatively straightforward. I can see this as a much more attractive proposition since there is the ‘carrot’ of a much wider audience.

 

Bearing in mind the Mathworks is unlikely to just halt development of Matlab and wait for Octave to catch up, there is never likely to be true compatibility between the two. However, I  think the point has arrived where there is sufficient similarity between core functions that it is possible to write simple m-files that will run on either with little or no change.

 

 

FREEMAT (v4.0)

 

This is a very polished product that immediately gives the impression it has been written for Windows. Although the installation worked on Win XP, 98 and 95, it was only really happy running under Win XP. This is fair enough since the only platforms that are claimed to be supported are XP and 2000.  

 

The user interface is very tidy including an integrated editor/debug, a path tool to add new search paths and an online help. The standard header-comment based help is still available, so user contributed content can easily provide some documentation and explanation of the functions.

On starting for the first time you will need to add the search paths to the standard toolboxes (io, funfun etc). Using the pathtool ‘add with subfolders’ option add C:\Program Files\ FreeMat\toolbox and then re-start the application, without the re-start the ‘path’ command returned paths to the previous v3.6 installation, even though this had been un-installed with the un-installer provided. I would suggest a re-start after any modification of the search paths, especially of you have problems accessing your m-files.

 

In terms of I/O, there are the standard C based commands for reading/writing to file and there is also system command support, so Windows “.exe” files can be called from within Freemat. There is mention in the documentation of commands to link low level code directly into Freemat. So there is the possibility in future, of 3rd parties developing integrated GPIB or DAQ toolboxes.  In the mean time a suitable data capture program could be run externally and the data retrieved from a temporary file.

 

Out of all the packages I have looked at, this one is the closest to a Matlab clone. It unashamedly aims to copy the best features of Matlab and hopefully improve on it in other areas. In this respect it scores well in terms of being able to share files. There are obviously going to be differences and omissions between Matlab and Freemat, but GUI’s and very high level functions aside, basic number crunching and plotting routines should run on either with minimal changes.

 

The last time I looked at Freemat (v 3.6) the graphics output was the main issue, it was very slow and let the rest of the package down. The graphics in v4.0 are much improved, graphs plot in a timely fashion, the default scaling is better and more of the handle graphics options are available. As with Octave, Freemat is basically a subset of Matlab, so it is going to be easier to write m-files in Freemat that will work on Matlab than the other way around.

 

Once installed Freemat v4.0 takes up around 57MB of diskspace, which seems quite modest by today’s standards. I know this is not very scientific but I always prefer software whose size is commensurate with what it does. So if you are looking for a compact Matlab clone with a good Windows style user interface, Freemat could well be the answer.

 

 

SCILAB  (V4.x)

 

This product has a very well supported host site and is being developed in very professional fashion, with defined goals, roadmaps and time scales. Versions 2.x / 3.x / 4.x and the latest 5.x are available for download. I have downloaded and installed versions 2,3 and 4 – all installed and ran without problem on Win95, 98 and XP. I have not tried 5.x due to my 56K connection (we are in very rural France) and version 5 is 76MB. The only thing to watch if you are using an older machine is hard-disk space. The installers can require 3-4x more room to unpack the files than the package finally occupies on the disk.

 

From a Matlab user’s point of view the main difference between Matlab and Scilab is the fundamental architecture. Scilab is much more like a traditional programming language such as C; functions and macros are not the same things. While a macro can be run by simply executing it (although even this requires the command “exec” not just the name of the macro), functions have to be loaded into Scilab and compiled before they can be run or referenced by a macro.

 

This is not really a problem if all the function definitions reside at the beginning of your macro. However, in the interests of a modular or function based approach it is easier to have functions stored as separate files. Ideally, once all your new functions are finished, they will be available as a complete library on start-up.

 

Making a library that is available on start-up appears to involve modifying the start-up file (scilab.star) assuming you have already worked out how to load, compile and save your functions. Producing help files for your functions involves updating the main contents file (list of libraries), creating a “whatis” file (contents list for the library itself), and finally the help files themselves using TEXT, XML, HTML or JAVA, depending on the Scilab version.

 

While none of the above steps is particularly arduous on its own, and the end result would be a very well organised extension to the language library, I cannot help feeling that it is all a bit fiddly and a long way from the Matlab approach i.e. Copy all your m-files into any old directory and tell Matlab where to look. Even if you knew nothing about Matlab except how to add one search-path and type the main macro name at the prompt, you could use the files.

 

I find this lack of functionality a little surprising since an awful lot of effort has been put into another feature of Scilab, a Matlab to Scilab translator. This attempts not only to convert the syntax of the Matlab commands but the actual program flow as m-files reference each other. The attempt at translation results in a rodent like population explosion in terms of the number of files. The actual files themselves have so many “type conversion functions” inserted, as Scilab hedges its bets as to what may be passed to the function, that the function becomes practically unreadable. This in turn makes the inevitable de-bugging process very difficult.

 

Aside:

 

I personally think that the Scilab developers have missed the main point about what makes a high level language (E.g. Matlab) attractive to a wide variety of users. It is about ease of operation and communication between users. There is no need to change the fundamental way Scilab operates, just provide the option of a fast-track way for users to exchange and run files.

 

Now I am no applications developer, but I cannot imagine it would be too hard to

make user written content easier to include by adding a few extra commands.

 

              For example:  mhelp myfunction - to list the first comment lines in the function/macro.         

mexec mymacro - to execute a macro.

mgetf myfunction - to load a function.

 

Plus a Matlab/Freemat style pathtool to add searchable paths for user defined functions.

 

 

Looking past the architectural details of Scilab, the graphical user interface (GUI) itself is very easy to use and intuitive on all versions. Later versions have an integrated editor and a very good cross-referenced HTML based help menu.  The graphics are nicely presented and have a good selection of commands to allow customisation and annotation of the output

 

In addition to the standard number crunching libraries there is Scicos, a Simulink equivalent, except this one is provided free.  System I/O commands are supported and work well, including running of external programs. User contributions include toolboxes for GPIB and DAQ interfacing, third party reports seem to suggest that they work well.

 

 

CONCLUSIONS

 

For Individual Products

 

Jmathlib, I couldn’t get this to run, so I can’t really say much more than that. If the installer goes to the trouble of putting a shortcut icon on the desktop, I think it should just work, and it doesn’t.  

 

Octave may well be an excellent tool on a Unix platform, but even the latest version cannot hide its command line origins. That said, it is now so close to Matlab functionally that it must be considered a strong candidate, especially if you want to write m-files in Octave that will also run on Matlab.

 

Freemat looks good cosmetically, works well functionally, and with the graphics improvements in v4.0 it has really come together as a package. Progress from here will largely depend on whether a good user base starts to emerge. Not having an academic heritage and echoes of Unix has resulted in a much more Windows-like piece of software. The downside of this is that there is not a ready made band of devotees to champion its cause.

 

Scilab is a very good piece of numerical modelling software in its own right. As such I think it should probably go its own way and not try too hard to follow Matlab. The architectures are just different and they both have their advantages. I think the overheads of Scilab requiring a more traditional program structure are balanced by the flexibility you gain from the lower level commands.

 

Overall

 

If I had to choose a freely available number crunching package for my own personal use it would have to be Scilab, simply because “it does what it says on the tin”. Even if the operating instructions are little harder to follow, the user-contributed toolboxes demonstrate that other users have found it worth the effort.

 

For a package to write small utility programs to share with other people, I would choose Freemat over Scilab. This is because if you type “Matlab files .m” into Google you find that there are thousands and thousands of m-files published on the web, the same is not true for Scilab’s .sci files. I think there is now sufficient compatibility  between Freemat and Matlab that it should be possible to write m-files in Freemat that will run directly in Matlab, thus reaching the wider Matlab audience and encouraging new users.

wp2e21edc9_1b.jpg

Matlab Alternatives

wp00ab985f.gif