Fundamental Types
The main data types in mathlayer® can be categorised into the following categories:
char type is defined as a matrix, and each row has to hold exactly the same number of characters:
This constraint can be limiting when variable sized strings need to be manipulated. There are two additional types under which arrays of strings can stored:
- Numerical
- Strings
- Tables
- Cell arrays
Numerical
Numerical data is stored either as double or logical. Double is to be understood in the sense of double-precision floating-point format and logical will hold either true (1) or false (0).>> [26 30 25 24]'#% creating a vector of doubles
26 30 25 24 >> [true true false true]'#% creating a vector of logicals
1 1 0 1
Strings
The most commonly used strings used in mathlayer® are of type char. It is the type of a variable created using single quotes as for instance in the following:>> charStr = 'this is a mathlayer string stored as a char'# this is a mathlayer string stored as a char
char type is defined as a matrix, and each row has to hold exactly the same number of characters:
>> invalidChar = ['a';'bc']% invalid because inconsistent number of characters per row
invalid dimensions >> validChar = ['a ';'bc']% adding a whitespace in first row to align elements
[validChar:2x2 char]
This constraint can be limiting when variable sized strings need to be manipulated. There are two additional types under which arrays of strings can stored:
- cell arrays of strings: the most flexible way of storing variable sized strings, at the cost of lower performance
- string arrays: format used to store non numeric data in table objects, less flexible than cell arrays of strings but provide higher performance
>> {'jack';'john';'alexander';'thomas'}#% example of cell array of strings
[jack] [john] [alexander] [thomas]
Tables
Table objects are objects that can hold different types per column. Let's define the following variables:>>% initializing variables
name = {'jack';'john';'alexander';'thomas'} age = [26 30 25 24]' subscribed = [true true false true]' [name:4x1 cell] [age:4x1 double] [subscribed:4x1 logical] >> t = table(name,age,subscribed)#% creating a table object from variables
name age subscribed jack 26 1 john 30 1 alexander 25 0 thomas 24 1 >> t.variabletypes#% displaying column types
[string array][double][logical]