So here's the deal with Matlab: Matlab is an oddball. In Matlab, everything is an array, and there is no real distinction between regular "values" and "containers" or "collections" like there is in many programming languages. In Matlab, any numeric value is a numeric array. Any string
value is actually an array of strings. Every value is iterable and can be used in a for
loop or other "list"-like context. And every type or class in Matlab must implement collection/container behaviors as well as its "plain" value semantics.
Scalar values in Matlab are actually degenerate cases of two-dimensional arrays that are 1-by-1 in size. The number 42
? Actually a 1-long array of doubles. The string "foo"
? Actually a 1-long array of strings. Everything in Matlab is actually like a list in Python (or, more accurately, a NumPy series or array).
A cell
array is an array of things, which can contain any other type of array in each of its elements. This is used for heterogeneous collections.
A char
array is a bit weird, because it is used to represent strings, but its elements are not themselves strings, but rather characters. Plain char
arrays are used in a weird way to represent lists of strings: you make a 2-D char
array, and read each row as a string that is padded with spaces on the right. Lists of strings that are different lengths used to be represented as "cellstrs", which are cell
arrays that contain char
row vectors in each element. It's weird; see my blog post about it. The new string
array makes most uses of other string types obsolete. You might want to use string
s here. In Matlab, string
literals are double-quoted, and char
literals are single-quoted.
The word "container" doesn't have a specific technical meaning in Matlab, and is not really a thing. There's the containers
package, but the only thing in it is containers.Map
; there are no other types of containers and no generalization of what it means to be a container. One of the Matlab developers had an idea for making containers like this, but it never really went anywhere. And as far as I can tell, containers.Map
hardly gets used at all: containers.Map
is a pass-by-reference "handle" object, whereas most Matlab types are pass-by-value, so Map
can't be used easily with most Matlab code.
So, putting aside the weirdness of char
s, everything in Matlab has array semantics, and is effectively an iterable container like Python lists or tuples. And in Matlab, most values and objects are immutable and pass-by-value, so they are more like Python tuples than Python lists.