FreeMat—Yet Another MATLAB Replacement

Many programs exist that try to serve as a replacement for MATLAB. They all differ in their capabilities—some extending beyond what is available in MATLAB, and others giving subsets of functions that focus on some problem area. In this article, let's look at another available option: FreeMat.

The main Web site for FreeMat is hosted on SourceForge. Installation for most Linux distributions should be as easy as using your friendly neighborhood package manager. FreeMat also is available as source code, as well as installation packages for Windows and Mac OS X. Once it's installed, you can go ahead and start it up. This brings up the main window with a working console that should be displaying the license information for FreeMat (Figure 1).

Figure 1. When you first start up FreeMat, you are given a fresh console.

As with most programs like FreeMat, you can do arithmetic right away. All of the arithmetic operations are overloaded to do "the right thing" automatically, based on the data types of the operands. The core data types include integers (8, 16 and 32 bits, both signed and unsigned), floating-point numbers (32 and 64 bits) and complex numbers (64 and 128 bits). Along with those, there is a core data structure, implemented as an N-dimensional array. The default value for N is 6, but is arbitrary. Also, FreeMat supports heterogeneous arrays, where different elements are actually different data types.

Commands in FreeMat are line-based. This means that a command is finished and executed when you press the Enter key. As soon as you do, the command is run, and the output is displayed immediately within your console. You should notice that results that are not saved to a variable are saved automatically to a temporary variable named "ans". You can use this temporary variable to access and reuse the results from previous commands. For example, if you want to find the volume of a cube of side length 3, you could so with:

--> 3 * 3
ans =
--> ans * 3
ans =

Of course, a much faster way would be to do something like this:

--> 3 * 3 * 3
ans =

Or, you could do this:

--> 3^3
ans =

If you don't want to clutter up your console with the output from intermediate calculations, you can tell FreeMat to hide that output by adding a semicolon to the end of the line. So, instead of this:

--> sin(10)
ans =

you would get this:

--> sin(10);


Joey Bernard has a background in both physics and computer science. This serves him well in his day job as a computational research consultant at the University of New Brunswick. He also teaches computational physics and parallel programming.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.


Jony's picture

This is an excellent post. I learned a lot about what you talking about. Not sure if I agree with you completely though.

The biggest percentage

sollen's picture

The biggest percentage increase this year was in maintenance costs, which grew by 11.26% to 4.97 cents per mile, on average 60W 12V LED SUV driving Light for sedan owners. Average costs in all categories are lower for smaller vehicles and higher for bigger ones.

MATLAB is unique...

mishainfotech's picture

I think MATLAB is the unique software and there is no better replacement to it till now. It incorporates the real tools for the digital image processing geeks.........

Geek Guide
The DevOps Toolbox

Tools and Technologies for Scale and Reliability
by Linux Journal Editor Bill Childers

Get your free copy today

Sponsored by IBM

8 Signs You're Beyond Cron

Scheduling Crontabs With an Enterprise Scheduler
On Demand
Moderated by Linux Journal Contributor Mike Diehl

Sign up now

Sponsored by Skybot