This is an old revision of the document!
Table of Contents
Matlab - introduction
Given that NeuroElf is a Matlab toolbox with several features only available via the command line (at present at least), I want to give a short overview of Matlab, its features and how the user may be able to make better use of the available functionality.
First of all, Matlab can be regarded as a development environment with features such as a built-in GUI to inspect the current state (variables in the present workspace and their contents), editor with syntax highlighting, a debugging mechanism to run code step-by-step, and a powerful command line prompt.
But Matlab also comes with its own language (which shares many concepts, syntax elements, and features with other languages), and I want to highlight some of the most important features:
Language features
- the language is easy to use for prototyping, given its forgiving and user-friendly nature
- variables don't require a declaration but can be defined and have their datatype and dimension changed at any point within a program
- numeric variables are, by default, all created with a standard datatype of
double
, requiring little (if any) knowledge of numeric datatypes - storage of and access to variable values is organized in workspaces
- identifiers can be overloaded (e.g. built-in functions can be replaced by user defined ones), globally or separately in each workspace
- array indexing is available in multiple ways to simplify element selection (see datatypes and indexing page)
- array-based operations are highly optimized for speed and mostly support multiple CPU cores
- memory management is built-in (workspace-related garbage collection on variables no longer in use)
- Matlab comes with a vast repository of built-in and built-upon functions for mathematical computations, data in- and output, as well as visualization
- functions can return more than one output value/variable (without having to resort to compound/struct variables)
- the number of keywords of the basic language is extremely small (20 english words, besides operator symbols), as compared to about 60 for C++ or more than 100 for Visual Basic
- user-defined datatypes are (usually) based on a built-in datatype (struct) and allow object-oriented development
- with a built-in interface to compiled code (MEX), Matlab allows to translate computationally intensive operations (recursion, etc.) into compiled code for speedup
- built-in file format to store the content of variables in a binary format (incl. compression and platform independence)
Built-in functionality
On top of these features, Matlab comes with many, many built-in functions from a variety of fields, among them are
- mathematical functions (sum, mean, median, mode, standard deviation/variance, discrete derivatives, convolution, minimum, maximum, etc.)
- list and set related functions (sort, unique, intersect, setdiff, union, etc.)
- rudimentary statistical functions (histogram, correlation coefficient, detrending, etc.)
- matrix operations (inverse, pseudo-inverse, SVD, decomposition, etc.)
- graphical output functions (line, polygon, shape, surface, and scatter plot, annotations, etc.)
- GUI functions (figures, controls, callback handling, etc.)
These features make it usually relatively efficient to create code with complex functionality with just a few lines of code.
User-provided toolboxes
Mathworks additionally provides a user-defined toolbox area on their webserver, File Exchange, where users can upload their functions (or sets of functions, called toolboxes) which often allows users to solve even complex problems with a minimal effort, given that someone has already solved it before.
GUI elements
When Matlab is started (in its default configuration), the following “windows” (components) are available:
- command line (prompt): this allows to enter commands (expressions, assignments, function calls, etc.), call a system process, and control the debugging mechanism (workspace control, etc.)
- command history: a list of the previously executed commands (incl. those of previous Matlab sessions)
- workspace inspector: this window shows a list of variables in the current workspace (name, datatype, size, min/max value)
- if a variable name is double-clicked, a variable-editor window is added (or selected if already visible), allowing to inspect and alter variable content graphically
- current folder widget: file/folder browser showing the content of the “present working directory” (pwd), allowing to navigate the folder structure and select files
- a “file detail” view, showing the content of known file types (MAT files)
Additionally, Matlab comes with a built-in Editor, supporting syntax highlighting and augmenting several of the core features of Matlab, as well as a Profiler, a tool to identify bottlenecks in code, i.e. a help to improve the run-time properties (time and memory consumption) of user-written code.